# |
Jun 26th 2019, 22:42 |
mdotobie |
Makes sense @cnizzardini. Sounds like you can still throw some exceptions from your abstraction for a nicer developer experience though |
# |
Jun 26th 2019, 22:34 |
cnizzardini |
But if an engineer goes to use it wrong, it should fail fantastically anyways, even without a nice LogicException message |
# |
Jun 26th 2019, 22:33 |
cnizzardini |
@mdotobie my use case is different than that, pulling data from db and passing it into an absraction layer, would've been nice if was easy |
# |
Jun 26th 2019, 22:24 |
mdotobie |
I’ll use `debug()` on the `$form` object in the console and see if the output matches |
# |
Jun 26th 2019, 22:20 |
mdotobie |
That’s a good point. I’m not using `__dumpinfo()` directly but that output happens in the console right after the object is instantiated so Psy might be using it for output it and i just don’t realize it |
# |
Jun 26th 2019, 22:18 |
ndm |
@mdotobie Are you maybe dumping the form object? Like `debug($form)`? In that case it would be invoked from `Form::__debugInfo()`, but other than that, it shouldn't. Set a breakpoint or dump a stacktrace (`debug(\Cake\Error\Debugger::trace())`) to get more info about from where it's being called. |
# |
Jun 26th 2019, 22:14 |
slackebot |
the Table level anyway. |
# |
Jun 26th 2019, 22:14 |
mdotobie |
@cnizzardini if you are getting all your Person entity objects as the result of a query you can pretty much guarantee the ResultsSet will be all Person objects. If you’re building the entities from data you get from a form for instance then yes, you could technically create an array that had Person entities intermixed with entities of other types, but I’m not sure what you’d do with it. Attempting to save that array of entities would f |
# |
Jun 26th 2019, 22:11 |
mdotobie |
I thought that @ndm but when I use the console and do something like `$form = new App\Form\ApprovalForm` I can see the fields populated from the `buildSchema` method. It seems to suggest that it’s building the schema before I ever get to the FormHelper |
# |
Jun 26th 2019, 22:10 |
cnizzardini |
prob not, i am likely being too anal about exact arguments anyways |
# |
Jun 26th 2019, 22:09 |
ndm |
@mdtobe The form itself doesn't call it, it's called in various methods in the`\Cake\View\Form\Context\FormContext` class. |
# |
Jun 26th 2019, 22:09 |
mdotobie |
Are you creating the Person entities from some external data? |
# |
Jun 26th 2019, 22:08 |
mdotobie |
I assume you’d be getting the entities from a database query tho |
# |
Jun 26th 2019, 22:08 |
mdotobie |
That would be a `ResultsSet` |
# |
Jun 26th 2019, 22:08 |
cnizzardini |
And if its not an instance of that it throws a LogicException |
# |
Jun 26th 2019, 22:07 |
cnizzardini |
would be nice if I could define something as a collection of App\Model\Enity\Person |
# |
Jun 26th 2019, 22:06 |
cnizzardini |
not really |
# |
Jun 26th 2019, 22:04 |
mdotobie |
I’m thinking that’s what you’re going for @cnizzardini |
# |
Jun 26th 2019, 22:00 |
mdotobie |
if it encounters an object that doesn’t belong to that class in the array it will return false and fail |
# |
Jun 26th 2019, 21:58 |
mdotobie |
and then do something like `$isObjectCollection = $collection->every(function ($object) { return $object instanceof someClass; }); |
# |
Jun 26th 2019, 21:57 |
mdotobie |
You could then say `$collection = new Cake\Collection\Collection($objects); |
# |
Jun 26th 2019, 21:56 |
slackebot |
<mdotobie> |
# |
Jun 26th 2019, 21:54 |
mdotobie |
so lets say you had something like: |
# |
Jun 26th 2019, 21:53 |
mdotobie |
well you’d write a closure for something like Collection::every() |
# |
Jun 26th 2019, 21:53 |
cnizzardini |
like does it complain if I chuck in something goofy? |
# |
Jun 26th 2019, 21:52 |
mdotobie |
You’d need to make the base array into a collection first |
# |
Jun 26th 2019, 21:52 |
cnizzardini |
Does that just happen magically |
# |
Jun 26th 2019, 21:52 |
mdotobie |
you could use it for that. |
# |
Jun 26th 2019, 21:51 |
cnizzardini |
*collection of instances, you know what i mean |
# |
Jun 26th 2019, 21:51 |
cnizzardini |
But I want to verify that array is a collect of a specific class |
# |
Jun 26th 2019, 21:51 |
cnizzardini |
My use-case is I want to pass an array of objects as an argument |
# |
Jun 26th 2019, 21:51 |
cnizzardini |
Maybe its not what I need |
# |
Jun 26th 2019, 21:51 |
cnizzardini |
Hmmm |
# |
Jun 26th 2019, 21:51 |
mdotobie |
Some things automatically inherit from it, like `ResultsSet` |
# |
Jun 26th 2019, 21:50 |
cnizzardini |
*who |
# |
Jun 26th 2019, 21:50 |
cnizzardini |
why would have thought! |
# |
Jun 26th 2019, 21:50 |
mdotobie |
Yep @cnizzardini, it’s called Collections as well. |
# |
Jun 26th 2019, 21:50 |
cnizzardini |
Does cake have anything like laravels collections? |
# |
Jun 26th 2019, 21:30 |
mdotobie |
When a new Modelless Form is instantiated, I can’t for the life of me figure out how the `schema()` method is getting called. I can override the `_buildSchema()` method in the subclass, but I can’t see where `schema()` is getting called in the first place in order to get to the `_buildSchema()` method. It isn’t in the constructor. |
# |
Jun 26th 2019, 19:43 |
mdotobie |
I’ve reasoned that I can additionally create a new `ContextInterface` that I will call `GraphContext` that will be used by the `FormHelper` class to utilize the custom properties on each field in the `GraphSchema` |
# |
Jun 26th 2019, 19:41 |
mdotobie |
So @admad, I’ve spent the last few hours on the problem I was starting to discuss earlier and my first step towards a solution has been to write a subclassed version of the `Cake\Form\Schema` class. I’m calling it a `GraphSchema`. This way I can define custom properties for each field through the `addField()` method in addition to the `type`, `length`, `precision` and `default` fields setup by the parent `Schema` class. |