Comments (1)
I just came across this and I think the way cast works isn't properly explained in the documentation. All it does is instantiate an object and then map an array to public properties. It also won't work with any type that has constructor arguments.
I think you should use normalization - the following works:
$schema = Expect::structure([
'created_at' => Expect::type(DateTime::class)->before(function ($date) {
return new DateTime($data);
}),
]);
from schema.
Related Issues (20)
- Access the $items property in the Structure class HOT 3
- Add DateTime and DateTimeRange expectations HOT 2
- Schema from PHPSTAN array shape HOT 1
- Possibility to use Schema to create an array/object of Schema's default values.
- Allow recursive schema validation in tree structure
- False-positive security bug because of non-standard LICENSE.md file HOT 2
- Description attribute - Nette schema as an object representation for XSD / JsonSchema / WADL / ...
- Validator from class HOT 1
- Default value on i.e. string is not working as expected. HOT 5
- Support custom cast function HOT 1
- Tuple validation HOT 1
- castTo: foreach() argument must be of type array|object, string given HOT 1
- Type error with Helpers::getCastStrategy and DTO with constructor sice v1.2.5 HOT 1
- Adding new PHP Versions as experimental HOT 2
- Exception in ValidationException.php
- Warnings produced by PHP 8.3.2 HOT 1
- Possibility to validate callback signature HOT 1
- Add extend() method to Structure class
- Make processor class non-final so it can easily be mocked in unit tests
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from schema.