« first day (2658 days earlier)      last day (2287 days later) » 

12:00 AM
any criticism welcome
 
Wes
@Allenph ok now consider this
at the time you create a new entity (one that has an id) you don't know what it's id is going to be, because auto_increment
right?
ah @Tiffany game has ads
sometimes you need to wait for them to finish
 
I use an ad blocker :S
 
Wes
yeah but you need to wait regardless :D
 
I know :P
 
@Wes Yes...
 
Wes
12:04 AM
the solution to that that is very used in the ddd community is uuids
basically you need to replace all those Int $id with uuids
composer require ramsey/uuid
this seems overkill but it's very much required for a decent design
it's simple to use tho
it's basically just a function
 
@tereško Riga is the second most expensive property in this version of monopoly, heh
 
@Wes But then how will I know what the actual ID in the DB is when I update or delete or whatever?
 
Wes
the primary key gets to be the uuid @Allenph
not int autoincrement
 
WTF?
 
Wes
yes. we all do that. it's cool :P
 
12:08 AM
@Tiffany?
@Teresko?

For real?
 
Wes
wrong ping probably
 
what?
 
Use UUID instead of AI id?
 
I do not care about DDD
 
So you don't do that then.
 
Wes
12:11 AM
uuid is used by ddd people but it's not ddd only stuff
 
outside DDD, nobody cares about UUID
well .. ok, not nobody - if you are working on a huge site (think: scale of StackOverflow as minimum), UUID becomes quite useful option
 
Seems dangerous even though it's almost impossible to have a collision.
 
Wes
collisions can be handled easily
on that note, i never had one in 40m records :P
you need to use uuid4 tho
have a look at it
 
why do you keep leading him always further the rabbit hole?
he has basically 30 min to finish what he is writing
 
I can be here as late as I want.
I'll be here all night probably.
 
Wes
12:17 AM
@tereško i think this is important
it's the only exception
 
@Wes That leads to another problem. How do I know if the entity is persisted?
 
anyway, I am off to bed
 
Wes
you don't need to know. i mean you know it depending from what you are doing
 
@Wes Well that's a problem. How do I know when to INSERT and when to UPDATE?
Night @tereško. Thanks for all of your help. :D
 
Wes
gn \o
@Allenph forget about it now. i don't know why you want to know that
insert and update are two different queries
 
12:19 AM
What do you mean forget about it? If I don't know whether the entity is persisted or not how do I know which query to use?
 
Wes
you do know what query to use lol
why wouldn't you?
 
Becuase the ID is generated when it's constructed...not when it's persisted!
 
Wes
correct, and?
 
So when I go to persist the object...It will always have an ID.
Which means I don't know whether to insert a new record or update the old one.
 
Wes
you do know, because you are calling ->insert and not ->update
request is to /insert, so you know what's going on
 
12:24 AM
I know by the HTTP verb then.
 
Wes
yes
or whatever
 
Okay. I'll whip up these data mappers and repositories hopefully then.
I still don't know how to get the PDO object in a DRY way, but I'll cross that bridge when I come to it.
 
@Wes I used to play a ton of monopoly growing up. I'm just not familiar with this version.
...and we bended some of the rules
 
Wes
the monopoly i own is like 30 years old
it's in italian and it got italian Lira (£) rather than (€) :D
it's completely different
 
Wes
12:33 AM
dat indent
 
@Wes yeah, the version I played had $
@Wes tabs
 
Huh. I don't know why it's indenting like that.
 
Wes
@Allenph this->getTable don't need this
just use the plain table name
 
Why?
 
Wes
unnecessary complication
do that only when you have multitennant systems or something
 
12:35 AM
I already did it now.
But other than that?
 
Wes
simpler is better :P wait lemme read
@Allenph there is no such thing as CommentMapper
only PostMapper
which fetches both the post and its comments
 
You're sure?
That seems really weird. Why wouldn't the PostMapper just inject the CommentMapper?
 
Wes
no, because that would be slow
you need to select * from posts left join comments on ...
 
Okay...
Ugh. That seems so wrong...but okay.
How do I know what tables? Just hardcode them?
 
Wes
yeah
 
12:48 AM
going to watch netflix 😛 twas fun @Wes
 
Wes
:D \o lata
 
Wes
that will forever appear on my youtube suggestions
 
it's so great though
 
@Wes Why can't you just do a transaction?
These methods are getting really long.
 
Wes
12:54 AM
a transaction? :B
 
Ugh. I don't know. This just seems like a violation of SOC!
 
Wes
you can delegate to smaller classes, but the main mapper is just one
$postMapper->update($post);
$postMapper->create($post);
$postMapper->remove($post);
update() and create() also insert or remove new comments
Post is indivisible
it's not that you have $postMapper->addComment()
 
I was thinking more that the repository was the thing that made it indivisible...
But that's impossible with two transactions.
 
Wes
what's a transaction in your mind
 
A way to group queries together.
 
Wes
1:02 AM
no, a transaction is the atomic change between two states
transaction are implemented around services
means you don't need to touch them yet
you need a wrapping layer around services that runs the service calls in a db transaction
 
Concerning the task at hand though...I need to persist a Post. A Post has many Comment. How can I break up the PostDataMapper so that I'm not doing massive queries in massive methods?
 
Wes
$pdo->beginTransaction();
$postService->userAddsComment($userID, $postID, $commentData)
$pdo->commit(); // or rollback
ok so when you update a Post of course not everything has changed. the post might have 1000 comments, and you don't want to update them all
 
@Wes Sure, but what about a fetch? What happens when I need to get a bunch of comments, instantiate them, then get the post, then instantiate post and add comments?
@Wes Okay.
 
Wes
what does that tell to you?
been trying to explain this to you for ages, we might finally be succeeding :D
 
@Wes That I need to determine which ones have changed?
 
Wes
1:08 AM
@Allenph right now your architecture is this
you fetch a post and all its comments in order to update the post or one of its comments
means that in order to change the post you are fetching like 1000, 2000 comments to that post
that's not good, right?
why would you fetch 2000 comments just to update the post?
 
Yes...
 
Wes
that is a sign of the fact that your aggregate (Post and its comments) is too big
it should actually be two aggregates, Post and PostComment
so that you can handle them separately
makes sense?
 
Yes. That does make sense.
 
Wes
so back to the aggregate
create a folder PostComment near the folder Post
move Comment into it
remove CommentCollection altogether
and make sure that Post doesn't reference the collection
Comment only need to know the uuid of the Post
 
Every comment has a post instead of a Post having many comments?
That part doesn't make sense.

This seems like we're going back to "Model = Table".
 
Wes
1:14 AM
small aggregates are good
so yeah aggregate = single lass is kinda a good thing
but depends
just trust me, do this change, i swear i will guide you through it all
i can't show you the final result, you need to understand why
 
Okay. I'm almost done.
@Wes There.
 
Wes
github.com/Allenph1/DDDPractice/blob/develop/src/Domain/… add Int $ownerPostId in __construct arguments
 
@Wes I was just noticing that. Already fixed and pushed.
 
Wes
now you can have a mapper for each of Post and Comment
and they operate independently
try to write insert, update, remove methods for them
 
Mornings
 
1:26 AM
@Wes Done. Pushed.
 
Wes
ok, got what you've done?
 
Morning @SaitamaSama.
 
Wes
rather than having Post and Comment objects referenced together somehow, you only reference Post by its id
 
Ahhh. I think it just clicked.
 
Wes
1:30 AM
$statement->bindValue(":id", $comment->getId());
you ar emissing this in update
but that's ok
 
Fixed. Haven't pushed yet though.
Okay, so what about retrieval @Wes?
Now I need a factory, don't I? And that factory needs to be an argument to the method.
 
Wes
now do this, create \Domain\Services\Post class
(although the name might be incorrect)
\Blog maybe
add the methods:
writePost(Post $post, Account $account)
editPost(Post $post)
writeComment(Comment $comment, Person $person)
editComment(Comment $comment)
that also might be incorrect tho i don't know yet
 
Services before fetching?
One second. I'm almost done implemented CUD on the other mappers.
 
Wes
the dependencies on that class will be the repositories of post account etc, everything that is needed
then try to write one of those methods
for example write post:
that's wrong though
 
woah, you guys have been having this conversation for almost ~4 hours
nice
 
1:44 AM
@SaitamaSama No. We've been having this conversation for almost a year.
 
Wes
writePost(PostWriteDTO $post, AccountWriteDTO $account)
editPost(PostWriteDTO $post)
writeComment(CommentWriteDTO $comment, PersonWriteDTO $person)
editComment(CommentWriteDTO $comment)
something like that
 
Wes
then
 
Wes
updatePost(PostUpdateDTO $postDTO){
$post = $this->postRepository->fetch($postDTO->id);
$post->setContent($postDTO->text);
$post->setLastUpdate(new DateTime());
// ... etc
}
 
1:48 AM
You lost me with the DTO bit.
 
Wes
$postDTO is a struct with the raw data you want to insert
class PostUpdateDTO{ public $id; public $text; }
in the controller:
$update = new PostUpdateDTO($httprequest->postdata->id, $httprequest->postdata->text);
$this->blogService->updatePost($update);
roughly
postRepository's fetch just calls the datamapper's fetch
repository and data mapper are very similar
i might need to go to bed though i'm a bit tired
 
Fuck.
 
Wes
it's 2 am here and i didn't sleep much today
but i just gave you the info to experiment a bit
 
I don't understand the DTO at all, nor how to do a fetch of multiple comments...
 
Wes
start with that updatePost() in the Blog service
 
1:52 AM
have moar coffee :B
 
I'll see if I can find some examples. Thanks @Wes.
 
Wes
the DTO is just a simple carry-data object
it doesn't contain logic
it's just raw data
 
I understand what it is. I don't understand why it's needed or where it comes from.
Something must translate raw POST data for example into the DTO.
 
Wes
3 mins ago, by Wes
in the controller:
$update = new PostUpdateDTO($httprequest->postdata->id, $httprequest->postdata->text);
$this->blogService->updatePost($update);
 
Why do I need the DTO?
Can't I just do the same thing with the actual Post object?
 
Wes
1:54 AM
you might, but i don't like that
 
Do you have a reason for not liking it?
 
Wes
because when you fetch from the database, you need to lock the rows
so you are locking the rows and it's maybe not needed
i want the services to do that, not whatever the caller is
the services are the wall again misuse
that's why they accept dumb data
 
Ahhh. You only update once instead of every property.
 
Wes
they wouldn't trust the incoming data anyway
but that's just me eh some might use the actual objects
 
The only other thing I'm confused about is what to do here...
function getByPostId(Int $postId) {
			$sql = "SELECT * FROM {$this->getTable()} WHERE postId = :postId";
			$statement = $this->getConnection()->prepare($sql);
			$statement->bindValue(":postId", $postId);
			$statement->execute();
			$data = $statement->fetch(PDO::FETCH_ASSOC);
			if ($data) {

			}
		}
 
Wes
1:57 AM
return $this->factory($data);

else return null or exception
factory looks like this
function mysqlToPostFactory(array $data){
    return new Post($data["id"], $data["content"]. .... etc );
}
the factory ultimately is just a function but you can put it in a class or whatever
it's not relevant how you do it
 
Do you use a factory for the individuals too or just call new in the DataMapper?
 
Wes
actually you could do that for now
forget factories
function getByPostId(Int $postId) {
			$sql = "SELECT * FROM {$this->getTable()} WHERE postId = :postId";
			$statement = $this->getConnection()->prepare($sql);
			$statement->bindValue(":postId", $postId);
			$statement->execute();
			$data = $statement->fetch(PDO::FETCH_ASSOC);
			if ($data) {
                            return new Post($data["...."], ....);
			}
		}
of course with factories it's better but you can't understand why at the moment
so for now just do that
 
I remember reading there was a reason for the factories...
 
Wes
there is, many reasons :D
 
I already started the factories. I'll do it that way. Thanks @Wes!
 
Wes
2:02 AM
right now it's not important
 
Fuck. I forgot. I still don't know where to instantiate PDO.
 
Wes
do it in the bootstrap for now
 
 
1 hour later…
3:13 AM
I was just experimenting...wondering if something like this is a bad or good idea...
function create(Array $row) {
			$post = new Post;
			$reflectionClass = new ReflectionClass($post);
			$properties = $reflectionClass->getProperties(ReflectionProperty::IS_PUBLIC);
			$propertyNames = [];
			foreach($properties as $property) {
				$propertyNames[] = $property->getName();
			}
			$reflectionConstructorParams = $reflectionClass->getConstructor()->getParameters();
			$arguments = [];
			foreach($reflectionConstructorParams as $param) {
				if (in_array($param->getName(), $propertyNames)) {
I'm not going to use it, but I thought it was interesting.
 
3:57 AM
@allenph you could also use Auryn::make with the second parameter.. would just need to prepend the ":" before the field names.
 
@Orangepill Good to know. I'm avoiding Auryn for this example. It's for my coworkers who know nothing of OOP and they would use it as a service locator 100%.
Hmmm...coding my first repository...problem I didn't anticipate. I have a method getByPostId on my mapper...I need it implemented on my repository. However, I'm not sure how to store my cache. How do I know if I have them all or not? o.O
 
Just have the repo consult the mapper on the event of a cache miss.....should work for a by id query.... group operations would be more problematic.
 
Is it worth it to loop through a cache organized by ID for one with a matching username or some other string, or should there be more than one cache?
 
4:16 AM
depends on what the usage pattern is .... personally I would favor simplicity and just consult the database every time until I could prove that caching would offer a measurable benefit.
seems like you are separating the components enough so that if caching is needed it can be introduced rather simply
 
Yeah. I'm trying. I'm going a little father than I need to. I'm going to need a code review by someone more experienced in the morning. I'm trying DDD, so probably Wes or Patrick.
Poor Wes. He's been trying to teach me for almost a year and spent hundreds of hours chatting with me. I feel like I owe him some money.
 
@Wes This is why each "type" of warning should probably be a behind a parameter.
 
Waddup Levi.
 
Evening.
 
morning room
evening LeviMorrison
 
Wes
4:30 AM
@LeviMorrison do you have some time now? dunno what time is it there
@Allenph sorry fell asleep
 
@Wes Have a few minutes.
 
Wes
ok so wordpress is a piece of shit @LeviMorrison it's all defined("FOO") && FOO
it's so stupid
that mega wall of errors is not useful and yes it should be optional unless it's really small
i have found another thing i could do
examine if define() was called with "case insensitive = true"
but i have so much data and i don't really know how to print it
 
@Wes Not really surprised.
 
@Wes Finished repositories! :D github.com/Allenph1/DDDPractice
 
Wes
all the codebase is like that
there are literally thousands of defined()
so the first section now prints conditional definitions, like
 
4:35 AM
Well for now I'd analyze something else. Like Drupal.
 
Wes
if(a){ class Bar{} }else{ class Bar{} }
it says, the class Bar has a duplicate declaration and only the first encountered is taken into account
the second section shows all the symbols whose definition couldn't be resolved
unfortunately in case of wordpress it's thousands
because defined() function_exists, class_exists... they are all over the place
so that section is not really useful
however even if i don't find the definition of constant AAA, i can check whether the constant AAA was always used using that very case
which is something
if they are not, then i'm printing those that are used using different cases
class names, functions, constants (also, unfortunately)
do you think i'm missing something?
 
Not sure.
Wordpress is garbage - we already knew that.
For now I wouldn't get too worried and try analyzing something else.
 
Wes
right now it's not really useful, i got the data but not sure how to analyze it :\
 
Should the controller just be calling a service, or should the controller instantiate the repository, etc?
 
@Wes What do you mean?
I'm not expecting you or anyone to fix these things automatically.
It finds the inconsistencies and possible conflicts.
 
Wes
4:45 AM
i'm sure i can do more but not sure how organize the output
anyway i will think about it more tomorrow
 
As long as the input is one issue per line you can use standard tools like grep to look through it.
 
Wes
@Allenph the repositories are injected into the services and they are not visible to controllers
 
@Wes Then why did you provide me with...
 
Wes
@LeviMorrison you can click the file link in the console and open it in phpstorm :P
 
function writePost(Post $post, Account $account) {

		}
That insinuates when the service is called, I already have a Post.
 
Wes
4:47 AM
3 hours ago, by Wes
writePost(PostWriteDTO $post, AccountWriteDTO $account)
editPost(PostWriteDTO $post)
writeComment(CommentWriteDTO $comment, PersonWriteDTO $person)
editComment(CommentWriteDTO $comment)
DTO, not Post
 
Gotcha. Thanks.
 
4:59 AM
Wait...isn't the service going to have a dependency on the repository? The controller has to create the repository and inject it into the service. o.O
 
Wes
the service's dependencies are the repositories
Blog has PostRepo, PersonRepo, CommentRepo as dependencies
 
Right...who instantiates those? The controller?
 
Wes
it depends. you want to know the ultimate design but again applications are all different
do it in the bootstrap, inject them in the controller
 
Jesus Christ...controller method looks like...
function writePost(Request $request, $repository) {
      $postService = new PostService($repository)->writePost(
				new Domain\Data\Repository\PostRepository(
					new Domain\Data\DataMapper\MySQL\PostMapper(
						new PDO,
						"post",
						new Domain\Data\Factory\MySQL()
					)
				)
			);
    }
 
Wes
inject them in the controller
class MyController { function __construct(MyRepo $repo){} }
 
5:12 AM
I don't know how to go any higher than this controller.
 
Wes
try cocaine?
i have no idea, higher than the controller there is the bootstrap.
bootstrap/front controller
 
Wes
if($controllerClass === "Post"){
    $controller = new PostController($repo, $foo);
}elseif($controllerClass === "..."){ ...
it doesn't have to be pretty for now
then you can make it pretty, with the dependencies injected automatically
 
What's hard is deciding WHICH repo to instantiate, my dude.
 
Wes
.... the ones you need?
 
5:23 AM
I don't know how to explain. The Route object that matches can only pass arrays. Do I just need to make a complicated DTO for every route?
 
Wes
no, just use that if
i'm saying that it doesn't have to be pretty at this stage
 
I don't understand what "that" is.
 
Wes
8 mins ago, by Wes
if($controllerClass === "Post"){
    $controller = new PostController($repo, $foo);
}elseif($controllerClass === "..."){ ...
 
I see that. You're injecting a Repo...the part I don't understand is how to build that repo.
 
Wes
just above it?
build all the repos there
dude you need to be a bit more practical
 
5:26 AM
I just don't understand where practical ends and shit code begins.
 
Wes
you probably were thinking already of something magical
don't try to be clever, you might get hurt :D keep it dumb and simple
 
This is what a DIC is for, isn't it?
 
Wes
if the suffering is unbearable then do something
like using a dic, yes
 
I'll try it your way. Then I'll look into Auryn or something when I've showed my boss. Thanks Wes. Much pain in the ass you have put up with.
 
Wes
now let's wait for teresko disrupting everything we did tomorrow :B
i'm sure he doesn't like the DTO bit
but again i don't like repositories being visible in controllers
 
5:34 AM
I didn't do the DTO bit.
I can't bring myself to do that. It seems extremely superfluous to me. I'm sure I'll be proven wrong soon.
@Wes But I injected the repository into the controller! WTffffffffffffffff.
 
Wes
goddamnit
i meant the services -__-
if($controllerClass === "Post"){
    $controller = new PostController($blogService);
}elseif($controllerClass === "..."){ ...
 
So the construction of the service need to be up higher a bit.
 
Wes
however teresko might suggest you to inject repositories in the controller
so it's not wrong
it's subjective
 
I think I'm seeing the merits of DICs. I'm going to use one.
 
Wes
i want everything to exist within the services or deeper layers
validation, exceptions, etc
 
5:37 AM
Wow. That seems literally impossible.
 
Wes
i like small controllers
 
@Wes Okay. Now what you said makes sense.
I was like "I can't throw exceptions in the entities?!"
I can already feel my boss saying ""no" and me quitting tomorrow.
 
Wes
for example what happens if an object in the aggregate throws? handling in the controller doesn't seem the appropriate place for me
because chances are you are going to delegate to another service for certain errors
 
I have done ZERO error handling.
 
Wes
it's ok ignore it for now
 
5:39 AM
Hopefully this is good enough to illustrate the concept even though it...you know...doesn't work.
Fuuuuuuuuuck. I haven't switched the IDs.
 
6:07 AM
morning ppl
 
o/
 
6:57 AM
o/
 
7:16 AM
morning guys
 
public function getIsActive(): bool how can I convince my coworker that this is a stupid name? I have tried everything :x
moin
 
function autoload($path) {
    $items = glob($path . DIRECTORY_SEPARATOR . "*" );

    foreach($items as $item) {
      if (is_file($item)) {
        if (pathinfo($item)["extension"] === "php") {
					include_once $item;
				}
      } elseif ( is_dir($item) ) {
        autoload($item);
      }
    }
	}

	/* Bootstrap Auryn...configruation loaded from ../src/Domain/DIC */
	$injector = new Auryn\Injector;
	autoload(dirname(__FILE__) . DIRECTORY_SEPARATOR . "../src/Domain/DIC");
WTF? The file I want is getting included but the variable is undefined. This should be in the same scope?
<?php

  $injector->define("\Domain\Service\HTTP\Post\HTTPPostService",
    ["\Domain\Component\Repository" => "\Domain\Component\Repository\PostRepository",
     ":\Symfony\Component\HttpFoundation\Request" => $request]
  );
@Patrick Why not isActive? if ($whater->isActive()) is way better than if ($whatever->getIsActive()).
 
7:40 AM
@Allenph i know, but he doesn't think it makes sense because he already named the variable isActive...
 
@Patrick If you're using setters and getters...which it appears you are you should hide that extra work in the flag itself. $isActiveFlag if he really wants to use dumb names...he should do it there.
 
Wes
7:56 AM
@Patrick what if you also have setIsActive($active) ?
genuinely asking
so yeah i'm still not sleeping
coffee kicked in
 
@Wes I'm about to blow my brains out over this stupid routing component and Auryn.
The code above should be in scope, yet I have to use global.
 
@Wes should be activate()/deactivate() imo
@Allenph no setters, only getters
 
reverie a state of dreamy meditation or fanciful musing: lost in reverie.
 
Regardless...same point.
I don't understand how Symfony's own fucking example doesn't work. Fuck it. I'm going to bed. Night all.
 
8:29 AM
 
Wes
yo
 
I am merging a git branch but it is saying everything up to date even the codes are different
I need the codes to be updated
how can i do that?
 
mornin
 
Wes
8:51 AM
are all php core constants case sensitive?
 

« first day (2658 days earlier)      last day (2287 days later) »