« first day (1753 days earlier)      last day (3421 days later) » 

user895378
20:00
@kelunik oic
@ircmaxell You mean I should just commit straight ahead to master?
@DavidGraham yeah, that's a shitty part in my approach. My mappers tend to retrieve all possible conditions :(
@bwoebi TROLOLOLO
user895378
Don't say "where's the RFC for that.," don't say "where's the RFC for that," don't say "where's the RFC for that" ... Hey Bob, where's the RFC for that change? DANG IT.
I only recently figured out that you should separate single entity and collection mappers .. and have not had time to revisit it to looks for better implementations.
20:02
@ircmaxell I sometimes have problems to interpret your "good luck with that" ^^
@DavidGraham I have been thinking of storing the list of set conditions in the collection itself, so that the mapper can know which have been applied
but I have not actually tried it out in a live project .. it might be a dead end
so you might consider a mapper call like this in the future $foo = $mapper->fetchByHireDate($date); ?
@DavidGraham no, because I want need an ability to use several mappers on both single entity and a collection of entities
that is too powerful feature to give it up
about a year ago I got a project where I had to work with a REST-like API (which was still in developments)
in one of the execution pats I ended up with 4 mappers for same entity (it was user data retrieval)
@kelunik Oh nice. /me likes!
Most of the time you don't need something to mass update (unless it's a specific maintainence), or a need to find something in a collection so specific for a write operation, but would you scoff if you saw something like $foo = $mapper->fetchByHireDate($date); ?
20:06
@tereško on your returned collections to you use a entity specific collection or a entity + storage specific implementation.
@ircmaxell so… what do you really suggest?
@Orangepill can you put this in different words?
my english seems to be detiriouting
@teresko you you retun a UserCollection or a UserCollectionPDO instance if you get my meaning
Also, it seems like @tereško has no problem calling mapper from entity methods. In DDD it is under debate on whether entities should ever touch persistence.
your english is fine... I am bad a words
20:08
@DavidGraham it's the other way around
I call entity methods from mapper(s)
In other words. The application should do something with entities then decide if they will pass them to the mapper.
oh
So your application doesn't fill an entity first then call a mapper for saving?
You pass the data to a mapper, and it fills an entity and saves?
basically, in that one case when I had 4 mappers, I was retrieving user from: (cookie + (session or mysql)) or rest
@DavidGraham forgive my setter,s but here will be a simple example
here's what people do: $fixedbugs = $em->getRepository('Bug')->findAllFixedBugs();
class BugRepository extends EntityRepository
{
    public function findAllFixedBugs()
    {
        return $this->_em
            ->createQuery("SELECT b FROM Bug b WHERE b.status = 'fixed'")
            ->getResult();
    }
}
$user = new User;
$user->setName('Foo');
$mapper->store($user); // new user is made
yeah I like that. That's what I started with before I did research and got all worried.
20:13
$user = new User(42);
$mapper->fetch($user);
$user->setName('Bar');
$mapper->store($user); // user is updated
yup
but $mapper should put new id into $user right? (on condition that previous id was blank or 0)
in this line $mapper->store($user); // new user is made ?
@DavidGraham yes
right, if it exists then hydrate the id
ok
if you call echo $user->getId() after that line, it would return the ID of newly created user
20:14
yup
so there is a $user->setId($id)
that mapper uses
yes, in my code there is
with condition that the current id must be blank or 0 (ie. new)
ok coooooool
I've been calling mapper the repository
Do you notice that lots of people do that?
or is it just me?
may mappers ALWAYS check for primary key, and if that is empty, it assumes that you are trying to store a new entry
I used the terms interchangabley
aw
It seems that people relate to the term repository more (ie. because of Doctrine2 I think)
20:17
doctrine isn't actually all that widely used
hmm....taking that to lunch to read now....
when you are interacting with online communities, you get a distorted view on general population
@Ocramius taking that as well to lunch for reading now
right
Many (MANY) developers still have AbstractFoo extends Foo extends Core extends Db extends Config extends App
20:19
.. implements IAbstractFoo
Yeah, people use inheritance like crazy
Oh, in general people do weird things. The other day I refactored this code into simple function calls:
I tend to think there is chance for big bloat that way. I like to leave inheritance as an option. Like if you dont' want to do a bunch of "->setSomething" and setup the object, then extend it and call your own "init" or something. Then you can use that extended object already setup.
$methodCall = 'foo';
$methodArgs = ['bar', 'baz'];
require 'callMethod.php';
actual code I've fixed yesterday :|
I was actually splitting the mapper functionality into two classes.. one that translated between an entity of a specific type and a vanilla data structure and one that implemented the persistance of that data structure. After going that route a while I realized that those two concepts where intristically coupled and I really didn't gain anything by separating them into two classes so I have been rolling them into one.
20:21
wow
@Ocramius Fixed?? you mean it didn't work
@DavidGraham yeah, I fight setters with a passion
@Orangepill well, fixed as in not having superglobals like $methodCall still floating around and breaking other stuff
@Ocramius What was in callMethod.php, just call_user_func_array()?
thanks @Orangepill
@Trowski no, a big switch case.
20:23
@Ocramius I was just talking about setters with @tereško
@Ocramius Oh, switching on the number of args?
It seems we need them for hydrating entities
no, switching based on $methodCall
Oh... that's unexpected.
@DavidGraham no need to use the public API to do something like that. The argument for that is mainly that this sort of operation has little to do with OO
20:24
@Ocramius I mean, I need to do things like:
$user = new User(42);
$mapper->fetch($user);
$user->setName('Bar');
$mapper->store($user); // user is updated
@DavidGraham you can use the named constructor approach as well...
oh, btw @Ocramius , since you are now online, can you tell us something about how Doctrine deals with changes in DB structure (like change in column name)
how is it handled?
D2 does that via reflection, and I thought many many times about it, and in the end it turns out that reflection is just fine for this task, and better than coding your entities for the sake of hydration
Sometimes we can find a method like "$employee->promote()" but other times we need more CRUD like tasks
Entity::createFromArray(["id"=>42, "name"=>"Bar"]);
20:25
@tereško we have a "schema manager" thingy that is quite horrible. We have a simple abstraction of the DDL (into some sort of AST), then we create one from the metadata, one from the existing DB and diff the two ASTs
this gives us all the DDL that needs to be executed to get to a change
@Orangepill bah, just reflect the shit out of that
@Orangepill what about changing like 3 things. Say an employee changed their last name, email, and favorite color?
there's no point to code something as horrible as createFromArray into your entity directly
if it had domain meaning, then fine, but this is pure technical stuff
so there's no added value in createFromArray
You either do "$employee->setLastName....$employee->setEmail ...." or you do "$employee->changeNameEmailColor()"
it even is something that is distant from the domain knowledge
@DavidGraham these are actual interactions, whereas he needs pure state setting
don't mix the two concepts. Setters used for hydration lead to a lot of mess/confusion
so sometimes setters are needed, right @Ocramius
20:27
@ocramius I was proposing it as a means to hydrate an entity and retain private properties.
@DavidGraham no, just use the reflection API
@Ocramius wasn't it based on /** comments in entity code?
Reflection is slow
@tereško that's one way of getting the metadata. We have XML|YML|PHP|ANNOTATION -> ORM Metadata -> Schema AST -> SchemaDiff (with existing DB) -> Schema AST DIFF -> SQL
@DavidGraham yes, but the CAN be cached
20:28
@DavidGraham it's not slower than your setters
really?
really.
that just blew my mind!
but....
20:28
use it ONLY (ONLY!!!!) if you are REALLY (REALLY!!!!!) sure that hydration is your bottleneck.
anyway, once you have a ReflectionProperty that is accessible, calling $prop->setValue($obj, 'foo') or $obj->setFoo('foo') has the exact same overhead
still though....like @tereško posted, many times you don't have a single method like $employee->promote(); $mapper->save($employee); and instead you just need to set stuff on employee then save
right
actually, reflection is even a bit faster than $obj->setFoo('foo')
so @Ocramius to be clear....
$user = new User(42);
$mapper->fetch($user);
$user->setName('Bar');
$mapper->store($user); // user is updated
That code is okay?
what's 42?
userId (primary key)
20:30
yeah
hmm, no, I don't think that's ok.
it is ok if fetch is renamed to refresh
what do you propose? (this is why I came to chat today, btw)
but a fetch operation usually creates the instance for you (or retrieves a cached one, if you use an identity map)
:) you assumed an infrastructure there surrounding that code (it's standalone, no ORM)
so new User() is an implementation detail of UserMapper#fetch()
20:32
what about this @Ocramius
$user = $mapper->getById(42); is how I normally would do it.
$user = $mapper->fetch(42);
$user = $repo->findById(42);
$user->setName("David");
$user->setEmail("[email protected]");
$repo->save($user);
what about that?
As @Orangepill said
@DavidGraham much better. Now the example is only flawed in the $user interactions
$user->setName("David");
$user->setEmail("[email protected]");
20:33
$repo->save($user) can update?
what does this mean? what is the interaction?
thank you for talking my language!!! @Ocramius
@iroegbu yar, don't see a problem with that
he's talking about "setters" now
$user = new User;
$user->setEmail('[email protected]');
$mapper->fetch($user);
$user->setName('Bar');
$mapper->store($user); // user is updated
20:34
so what do you propose we do different with those "setter" interactions?
I've been thinking to pass a DTO? or an array? I don't know
Well, you are setting a name and an email. What UI interaction is that?
is the user updating the profile?
so, you have to check within save() and call update or insert depending on if $user has an id
Just general form update. There's no method like "promotion" or "gotMarried"
@iroegbu yes, although I ended up stopping relying on auto_increment.
ping me someone, if I am needed .. I'm gonna read some manga
20:35
you can probably use UPSERT all the time
@tereško hf
(also, go read Sunstone, it's awesum)
@Ocramius this is a general update from a UI form. I know it would be good to have some method we call like "$user->changeStatus($data)"
@DavidGraham $user->updateFromProfileEdit('Bar', '[email protected]') is what I mean. No direct state transition, but rather interactions
@DavidGraham then code it like that :)
yesss
again this is why I came here! I was thinking exactly this
20:36
I found out over (sadly) multiple projects that devs tend to over-abstract via setters/getters, and then they save 10 minutes in writing the form logic
so $user->updateFromProfileEdit($array) what about that?
for spending weeks trying to disentangle it later, when the form interactions change throughout the domain/application
@DavidGraham yes, except that you'd either have a DTO as parameter, or single explicitly typed parameters
note that getters are fine: these allow forms to be populated with state (that's ok-ish)
ah ok
` $user->updateFromProfileEdit($dto)` perhaps from a command handler
still, even talking with Bernhard Schussek (Webmozart) he uses DTOs bound to forms to avoid coupling entities to form stuff, for example
yar
So it's ok for entities to use DTO's for interactions (on changing their state, etc)?
even if the DTO's will have many properties that seem redundant in that the entity has the same properties?
20:39
specifically about that one example, I disagree btw because:
- it makes the identifier a detail that is modifiable from outside the entity
- the entity is in an invalid state during refresh

In cases like that, I prefer using hacks ( [instantiator](https://github.com/doctrine/instantiator) ) and build the object without using its API at all
@DavidGraham IMO yes
yes, I love avoiding setters, because it creates a time frame when entities are invalid
@DavidGraham yes, the aim is keeping the domain language and core of the state intact and protected from outer layers
"the entity is in an invalid state during refresh" wut?
with a single interaction, you can do a single validation, and also capture the context
setters don't have context
@tereško new User(42) is not a valid user :-)
(lacks username, email, etc)
@DavidGraham correct.
20:41
yeah, but new User() can be....because perhaps a unique ID is all that is valid at first.
jeez , people, why it is so har to understand that it is a simple FUCKING EXAMPLE
@DavidGraham an empty object is valid? I don't think so.
@tereško oh, sorry, nvm then :)
Abe
Abe
@tereško lol
once an ID is set (perhaps after repo saves and updates the id, usine reflection) then it can't be set to another ID.
so there would be a condition of "if id is blank or 0"
@Ocramius validation is context dependent
you will have users that will put junk data into stuff because they want to save the form
@DavidGraham wrong
20:43
I think that validation is based on interactions
Validation of STATE is strongly enforced in core
Martin Fowler speaks of this
and is contextual in interactions with existing data
don't confuse form validation with core domain validation
20:44
I'm not
but when you require an email in the domain, then the form is going to require it
if you don't put one in
so what I'm saying is....
you may want to NOT require an email in the context of where that form is being used
Core validation for "BankTransaction" is that a "BankTransaction" object cannot exist without a date, a description and a value (usually a money amount). The ID is totally irrelevant here, for example (from a domain perspective)
therefore, building a "BankTransaction" with just an identifier breaks that sort of invariant and introduces possible bugs
that's what I was arguing about: when building an object, ALL of the required data should be there
when the object exists, then yes, the object is your context
Ok, so we have to go back to core validation and change it if people start putting junk in forms to pass them through right?
@DavidGraham yes, they'd simply make the app crash at first, and then you'd tune the forms to not make the app crash
I mean, constructor (what it means to be minimally valid)
righto
20:46
ok makes sense
I mean, you find that the real rules appear when users start gathering data (data you originally were told was absolutely required)
they find loop holes, where someone doesn't have a email or phone
so you do 2 things. 1) put in a filler character or something to pass validation 2) or update core minimal contructrion validation
One of those 2 options I mean
you have
@DavidGraham you have to do them both
actually, the frontend validation is optional (the form)
but you can't deploy something with a form where entering invalid data just causes an exception :P
(it's perfectly legit for APIs though)
yeah, i'm ignoring form (UI specific validation....ie. are there spaces in the end of the text input, etc)
@Ocramius I disagree quite strongly with this. A form is simply an API consumer.
I think he is talking about seperation of form validation from domain validation
the form may have more validation to do that is un related to domain
You can add whatever shinyness you like to the front end, it doesn't mean that it is exempt from the rules of the back end
@DavidGraham That doesn't mean it can outright ignore the domain though
20:51
yes, but whether there are blank spaces at the end of a text input or not really doesn't have to cloud up the domain
@DaveRandom a form is just nice UX attached to your domain interaction
the domain interaction is raw and explodes in your face if you do an invalid bank transaction at low level
the form instead has a validator that says "oh, you cannot do that, honey!"
whether the characters are UTF-8 may not be a domain concern
@Ocramius IMO the domain should do this as well
You can't just let things blow up
@DaveRandom perhaps you are misunderstanding me. I mean that domain throws exceptions and throws exceptions EAGERLY
(before state is modified)
Abe
Abe
@DaveRandom how would you do that?
20:53
and then you build shiny forms to prevent the exceptions from being what the user sees
things like paying twice for a shopping cart cause a throw ShoppingCartAlreadyPurchased::fromShoppingCart($cart);
whereas the form would simply have a validation rule that disables the button (and prevents submission) if $cart->isPurchased()
the form is a layer of "nice and friendly" on top of the exception that you coded upfront
if the user (somehow) manages to work around your frontend validation (new app, API interaction or simply somebody with a backdoor) then you should get a ShoppingCartAlreadyPurchased exception and a 500 or whatever is appropriate (not that important at this point, but you can tweak it)
$user = $userRepo->findByID($id);
$user->updateFromMainForm($dto);
$userRepo->save($user);
Is that ok?
I still tend to work as if JS doesn't exist from the bottom up, maybe I should stop doing that but it makes me uneasy not spitting out friendly things that obfuscate the back-end panic at all layers
save what? :P
$userRepo->save($user);
and the repo uses reflection to update the ID
20:57
@DaveRandom oh, I don't do this stuff in JS, all PHP
also uses reflection to hydrate the entity from $userRepo->findById($id)
@DavidGraham please no
@DavidGraham just use a UUID there
so that the integrity is guaranteed BOTH with and without repo interaction
@Orangepill right, updated code snippet
20:58
@Ocramius When you say form you don't mean an html form you mean a DTO that represent the form's content
Abe
Abe
@DavidGraham i don't like that
@Andrea we'll need to get you a better mic
@Orangepill I mean the HTML form + validation
@Ocramius Ahh OK then maybe I did misunderstand, you are talking about (for simplicity) the M vs how it's presented via the VC?
$user = $userRepo->findByID($id);
$user->updateFromMainForm($dto);
$userRepo->save($user);
Everyone, paste your alternatives to this approach
Abe
Abe
20:58
especially because of how you named the method :P
domain model => guarantees state consistency and throws exceptions like paranoid
form (in presentation layer) => simply prevents you from reaching those edge cases by saying "no, that can't be negative!" and similar
@Ocramius Ah OK then I'm on board
I can't use an UUID because the database already exists
@DavidGraham I like that approach
Abe
Abe
i don't like entities having to know anything related to forms and things

« first day (1753 days earlier)      last day (3421 days later) »