Req #81203 [Com]: [ FEATURE ] StructType like interface for arrays

From: Date: Sun, 27 Jun 2021 22:40:05 +0000
Subject: Req #81203 [Com]: [ FEATURE ] StructType like interface for arrays
References: 1  Groups: php.bugs 
Request: Send a blank email to php-bugs+get-234653@lists.php.net to get a copy of this message
Edit report at https://bugs.php.net/bug.php?id=81203&edit=1 ID: 81203 Comment by: rtrtrtrtrt at dfdfdfdf dot dfd Reported by: 6562680 at gmail dot com Summary: [ FEATURE ] StructType like interface for arrays Status: Wont fix Type: Feature/Change Request Package: *General Issues Operating System: Win10 PHP Version: Irrelevant Block user comment: N Private report: N New Comment: your problem is that you confuse programming language with framework Previous Comments: ------------------------------------------------------------------------ [2021-06-27 22:18:53] 6562680 at gmail dot com Main thing of this request is ask you guys to implement type that allows match some object without creating class and implementing interface. Interface segregation is about SERVICE layer, datalayer always has a problem with damn extend/composite. Correct library should have enough objects to be published, but almost all the projects needs to be written faster. Language should give options to write faster. Generics allows to skip code generation - i need to write code generator every project to just generate damn entities by database for doctrine/eloquent + repositories + so on stuff cause of you, guys can't just create syntax like: ``` $repo = $entityManager->getRepo<EntityClass>(EntityClass); ``` i always need to create some phpdoc stuff /** @var EntityClass $repo */ or even create adapter class. Class nesting allows to reduce size of dependency injection layer - declined long time ago, currently i need to create factory with public methods everywhere Readonly props reduces count of public setters - there is no thing Structs allows to use global objects without mappers and without creating tonns of classes. It works like your typehinting where you define "string" - it maps any type to your and check it is possible (Interfaces cannot do that! It is required on DAL layer every second!!!) Decorators allows to configure dependency injector directly in your class and also allows to configure even router BEFORE call the method and allows to collect it by class reflection. - Currently we install Doctrine AnnotationReader (if you see how its realised - you prefer the death) - everytime... You have to ignore requests to create arrow syntax to launch functions and think about how make language EASIER TO WRITE, not MORE FEATURED. As i see your main idea - give community opportunity to solve anything as they want - creates anti-patterns, pseudo-patterns, "experts" and "bloggers" - but really we wont to create CRM in several people - we need damn team cause of tonns of symbols we need to print in IDE. Thank you. ------------------------------------------------------------------------ [2021-06-27 20:57:41] requinix@php.net I can't tell what this "struct" thing is supposed to be, but the bulk of what you wrote (as far as I could understand it) pertains to validation. Data validation is not a job that should be performed by the PHP language itself, and there are plenty of frameworks and libraries and design patterns that can handle the job. ------------------------------------------------------------------------ [2021-06-27 14:08:48] 6562680 at gmail dot com Description: ------------ Every project every day we implement Serializer to convert incoming JSON data into nested object tree with validate the data. Main idea is about spliting your project into modules. I give an example: You have two modules - Auth and Company Auth module needs something like User or Identity or User interface But the Users by the task is depend from... maybe Agency or business network. So you need User class inside Company module Also you need User class inside Auth module (or some of its representation) Once you extend Company's User you create Hard link that should be resolved with maybe Interfaces. But your Auth User class still not implement Interface from Company class, so even if you create interface - you still need to create class that extend or realise original one. Everywhere that problem is solved using maybe Doctrine - there is a Entities (with damn annotations, relations and so on, required only for DAL layer) - and now you project is working only if you have DAL layer with all Entities. You cannot build small module with ValueObjects + Interfaces - because DAL layer needs then you interfaces implemented on Doctrine entities. But Doctine entities forbid to set id attribute and also have additional Event handlers like prePersist/postPersist, constructors, cloners and stuff that is required ONLY in DAL layer. So every application becomes a monolith, linked, related and coupled. Somebody decides to use Microservices then. They write own Message Bus... same like base PHP stack trace. Somebody decides to implement EventDispatcher and then everyday tries to build event call tree to control what exactly was first, second... etc. Main problem here is YOU CANNOT JUST VALIDATE objects or arrays in 2-3 lines of code. Serializer solves it like walk recursive and json and then maps incoming array into your entities/requests/valueObjects, then we need annotations to validate, and then - if some task expects little different data from global one - you need to implement almost layer to do that. How about implement global type (like interface) named Struct (YourObjectStruct) and create validator that can: 1. validate array 2. return errors in nested array 3. return array or map array to structs like serializer does ``` class UserStruct { public $prop1; public $prop2; public $prop3; public static authorize() : array { return []; } public static required() : array { return []; } public static rules() : array { return []; } } ``` ``` class UserRequestStruct extends UserStruct { public static authorize() : array { return []; } } ``` that structs could be controlled with next service: ``` interface StructerInterface { // returns bool public function fails(value, rules, messages, labels) : ?ValidationInterface; // returns validation if failed public function verify(value, rules, messages, labels) : ?ValidationInterface; // returns validation if succeeded // throws exception on fail public function validate(value, rules, messages, labels) : ValidationInterface; // returns errors array (you can pass existing validation to extract errors from) public function errors(valueOrValidation, rules, messages, labels) : ?ValidationInterface; // returns tree of struct object // throws exception on validation failed public function unserialize(value, rules, messages, labels) : object; } ``` Main thing of the concept - create local interfaces to check incoming object with properties. You can pass your object without any interfaces, object would be converted to array, validated and then used like "match our local interface" It works on frontend for example typescript. There isnt "data interface", ts just inspects on IDE (that is dangerous, but allows to use StdObject without creating Domain class, you just sure you pass that data like interface So you can use your arrays or convert it into object tree, and you need interfaces only for services instead everywhere everysecond. Thank you. ------------------------------------------------------------------------ -- Edit this bug report at https://bugs.php.net/bug.php?id=81203&edit=1

« previous php.bugs (#234653) next »