« first day (2477 days earlier)      last day (2461 days later) » 

12:03 AM
@JapanGuy you can add a <input type="text" name="url" style="display:hidden"> in that form
if you see a content in $_POST['url'], then it is spam
 
@tereško oh that makes sense! thank you! will do now.
oh and one more thing
 
you can use any of the "common field names"
 
i am trying to track it down but
my access.log file is empty and
the log files that have been updates within this week are error.log other_vhosts_access.log suexec.log
 
look at the vhost's access
 
@tereško
all the lines are like this
localhost.localhost:80 127.0.0.1 - - [27/Jul/2017:15:22:36 +0300] "OPTIONS * HTTP/1.0" 200 126 "-" "Apache/2.2.22 (Debian) (internal dummy c
onnection)"
 
12:07 AM
all?
 
until the attack started, then i have these
localhost.localhost:80 127.0.0.1 - - [27/Jul/2017:15:32:00 +0300] "-" 408 0 "-" "-"
 
ah, fuck
 
yea almost all
 
do you have multiple sites on that box?
 
yeah i have two
the other one is fine
 
12:08 AM
what's your apache's vhost config like?
 
its a subdomain
 
it seems that you have not configured logging for vhosts
 
12:29 AM
@tereško thanks for the advice, i found my vhosts config file and the access.logs were in a slightly different folder
 
 
1 hour later…
1:48 AM
@WesStark How does one deal with read specificity in the Repository Pattern?
 
read specificity?
 
<?php

  namespace User;

  class Repo
  {
    function getUser($id)
    {
      // Get a user.
    }
    function getReallySpecificUserByABunchOfRandomFields($foo, $bar, $foobar)
    {
       // Get Really Specific User
    }
  }
@WesStark
Furthermore...mass updates? Deletes? Very specific mass reads?
 
you don't write generic apis, you write exactly what you need. even at risk of being redundant
 
@WesStark That sounds lame and complicated. For instance...
<?php

  class someController
  {
    function getReallySpecificUser()
    {
      $repo = new User\Repo();
      echo json_encode($repo->getReallySpecificUserFromSeeminglyRandomFields($_GET['random'], $_GET['field']));
    }
  }
It seems like the method naming complexity would end up FAR more complicated than SQL very quickly.
And with none of the standard syntax.
@WesStark
 
you aren't writing the api for phpmyadmin. you know what your domain requires, and it's a finite set of operations. you are trying to cover all the things instead and trying to generalize your api. also you must be very descriptive about it, like getPersonByDrivingLicenseID, getPersonByID, getPersonBySanitaryNumber (whatever you call it in the us) etc.
 
1:58 AM
@WesStark I understand that...but it seems more efficient (don't kill me) to get an Eloquent collection.
I send the same information...in probably less characters...in a very standard way.
 
more efficient, how?
 
I don't have to know a specific method. I just know what i want.
 
...know a specific method?
doesn't seem to me a big effort :P
 
@WesStark DDD is about using plain English and understanding the domain the same way in code as your client does in speech, if I understand correctly.

It's far more complicated to recognize every developers method naming standards than to know the attribute names on your objects!
Plus, another question I had adds on to this one. There will be a derivation of this for mass operations as well!
 
you are not abstracting away the persistence layer, you are exposing it like a fat naked guy on a non nudist beach
and no ddd is not about "using plain english"
 
2:03 AM
183
Q: Proper Repository Pattern Design in PHP?

JonathanPreface: I'm attemping to use the repository pattern in a MVC architecture with relational databases. I've recently started learning TDD in PHP, and I'm realizing that my database is coupled much too closely with the rest of my application. I've read about repositories, and using an IoC containe...

@WesStark This guy has a solution to my problem...but it seems just as bad as Eloquent.
Providing specificity in objects is essentially what Eloquent does with arrays.
 
don't look at what others do, we all do different things. i know it's scary
 
It seems like you'd end up with a billion methods on the repository...
@WesStark Are you in a bad mood or are you tired of my incessant badgering?
 
I believe you can group some of them...
 
did i sound in a bad mood?
it's just my poor english. i'm not in a bad mood, actually i love discussing about these things :B
for instance everybody agrees on what the repository should do, but not many agree on how the "save back to database" should work, and who is directing it
 
getUserByID($id), getUserByEmail($email)... can all call private getUser($field, $value). You make it all as simple as possible
 
2:07 AM
i can only tell you what i do at the moment and what i think it's my best interpretation, again at the moment
but i frequently change my mind
 
But, what Wes said is best... be explicit.
 
@IROEGBU That is what I was just talking about though.
You're essentially abstracting regular queries into a method name.
Which is LESS standard and would take more time to understand than an SQL statement.
@WesStark So, really...there's no good answer. You just have to...deal with it.
Somewhere you're going to have either complex SQL queries, or complex method names.
 
You should keep it as simple as possible, avoid query builders if you can
 
in ddd you either have plenty of small queries or a few big queries
 
Or just use Doctrine ;)
 
2:10 AM
@IROEGBU Your suggestion is essentially building your own query builder then abstracting it with method names.
 
the good thing is that they don't change
you don't need to change the sql, only the parameters
 
Hmmm.
I'm working on a small "DDD" example. Hoping to understand as much as possible and THEN let people tear holes in it.
One more question. How do you handle transactions which span multiple repos?
 
you need to start from the aggregates. suggest some business domain that both of us know?
like, soccer champioship rankings, with teams, players and stuff. something like that
would that work?
it's hard to explain something that revolves around the domain, without a domain we both know and that we can use as example
 
Say I have a small application which has soccer players, and teams. Each player has an address, and so does each team. Suppose I consider a team an aggregate, and a player an aggregate. When the player repo persists a new player it needs to contact the address repo. In this case, the act of persisting the player will consist of a transaction of persisting the player object and an address object.
How do I code the address repo so that it knows to "hold its horses" and be part of the transaction?
 
ok so in this case you have 3 aggregates, Location, Player and Team
 
2:21 AM
@WesStark I thought that an aggregate was essentially a transaction boundary?
 
no
transactions can span multiple aggregate types, or multiple instances of the same aggregate
> When the player repo persists a new player
that's not a proper operation. you don't do generic operations, you do stuff like
ContractsService::playerIsBoughtByATeam($playerID, $teamID)
function playerSubscribesContractWithTeam($playerID, $teamID){
    $player = $this->repositories->player->fetchByID($playerID, Repo::LOCK_FOR_WRITE);
    $team = $this->repositories->team->fetchByID($teamID, Repo::LOCK_FOR_WRITE);

    $team->getPlayers()->add($playerID);
    $player->setTeam($teamID);

    $this->repositories->saveAll();
}
$team->getPlayers()->add($playerID); // notice how it's not $player, but $playerID
$player->setTeam($teamID); // notice how it's not $team, but $teamID
that's because an aggregate can reference other aggregates only by id
if you did that, they would be the same aggregate, not two separate ones
makes sense?
@Allenph
 
@WesStark, No. I'm confused.
Suppose a there is a new player...never heard of by the application.
 
you don't want to have overlapping aggregates, nor duplicated data
 
You've lost me.
A player BELONGS to a team. But...a player is its own domain object.
 
2:37 AM
class TeamAggregate{
    public $teamName;

    public $playerIDs = [];
}

class PlayerAggregate{ // this is a separate aggregate
    public $playerName;

    public $teamID = NULL;
}

VS:

class TeamInclusiveOfPlayersAggregate{
    public $teamName;

    /** @var Player[] */
    public $players = [];
}

class Player{ // this is a class of TeamInclusiveOfPlayersAggregate now
    public $playerName;
}
 
@WesStark So only aggregates should have repos?
 
yes. 1 aggregate 1 repo
 
@WesStark The player should not have a repo?
 
depends on which of the two examples i've posted. the first will have two repos as it has two aggregates
TeamAggregate TeamRepo
PlayerAggregate PlayerRepo

the second will have one repo for the only aggregate it exists
in red the aggregates
within them the objects or the value objects, in green
within the aggregate all objects have access to other objects in magenta
but each of these objects cannot access other objects in other aggregates, if not by id, foreign key, whatever (in blue)
 
@WesStark I see. So the fact that aggregates are persisted in their own transactions is a natural result of them containing value objects without each of those objects having their own repos.
So, in the second case...all actions pertaining to players will have a method on what object?
 
2:44 AM
again transactions can span multiple aggregates
each service method is a transaction
 
@WesStark I don't understand services then.
 
and service methods's goal is managing the relationship between one or more aggregates
 
Gah. I have spent months trying to understand this. Months. I feel like I am going in circles.
 
17 mins ago, by Wes Stark
function playerSubscribesContractWithTeam($playerID, $teamID){
    $player = $this->repositories->player->fetchByID($playerID, Repo::LOCK_FOR_WRITE);
    $team = $this->repositories->team->fetchByID($teamID, Repo::LOCK_FOR_WRITE);

    $team->getPlayers()->add($playerID);
    $player->setTeam($teamID);

    $this->repositories->saveAll();
}
 
That is a method.
Services are not their own objects?
 
2:46 AM
that is a service method
 
That just made a lot of stuff click.
 
as you are creating a transaction that spans two repositories, player and team
and saving it back to database
 
Wait.
The player MUST be a class.
It has a method.
 
correct
it is a class in the Player aggregate
 
I'm going to go try to code something.
 
2:48 AM
and happens to be the Aggregate Root of that aggregate
 
Mind if I ping you in an hour?
 
function registerNewUser(UserDTO $userData){
    $user = new UserByDTO($userData);
    $this->repositories->get("user_repository")->add($user);
    $this->repositories->saveAll();
}
sure
i'm going for a run now though
should be at home in 1 hour
 
morning
 
3:25 AM
@WesStark It's going to be more than an hour.
I have to rewrite my framework. I haven't used this in 6 months. It's absolute garbage.
 
3:42 AM
45' the usual 11km ish track. must be the first time that i wasn't exhausted at the end. i don't understand the pattern. i didn't even sleep properly tonight, and ate not particularly energetic stuff
 
4:00 AM
wait for it...
 
@WesStark Don't know. I don't run much. I used to. I had nights like that also. I think I did best when I was thinking about other stuff.
 
yeah if you focus on the pain you are finished
 
Question. As I'm rewriting this framework, I'm coming to realize that most of what I was writing was the router and the bootstrap for Eloquent and Twig. It seems like the router might have been the only thing I actually wrote...and the "framework" was just that router (badly written) tightly coupled to a directory structure, server, Eloquent, and Twig.
 
Exception::__toString truncates message at null byte – #74999
 
^ boom
@Allenph try to build an application, then make small bits reusable
i mean, don't do the opposite
 
4:04 AM
I decided my DDD example should be a rewrite of my router. But then I wondered...how do you implement DDD in a setting that does not have persistent models?
Take this scenario for instance...
 
@wes as I said, it's truncated in a couple places. e.g. 3v4l.org/9uWqh
 
@PaulCrovella You do? Say the first word in the song Roar.
 
The only thing I could foresee is a repository pointing to an object.
However, that object seems like it would be a God Object...
 
@PaulCrovella i'm not sure how it does that lol
@Allenph there are certainly bits you can reuse for a framework, but you shouldn't attempt to write them now
 
@WesStark Well...I need a router to even start this.
I don't know any. Could it not be a good idea to start with writing one?
 
4:14 AM
no you don't need that. ddd doesn't even cover controllers as i remember it
start with services
also for the record, i did not have controllers for ages and i had pretty sophisticated code
i just didn't care enough and i only had whatever.php, crap.php :B
obviously it was stuff not requiring "pretty urls"
people in this room use github.com/nikic/FastRoute tho
@Allenph ask me stuff. don't guess :P
 
@WesStark I'll take a look. I like MVC...I only like DDD because it seems conducive to MVC.
Plus, I've always been one to learn by reinventing the wheel.
In fact, I think I answered my own question.
 
What is the reason why PHP is used to build many popular sites, even if it’s considered to be a "bad" language by many developers?
 
DDD is about M only @Allenph but you can do MVC with DDD
 
@WesStark Exactly. I like MVC. I just don't like "single class = single model" idea.
 
hum?
 
4:26 AM
What's this DDD that you talk of? The graphical frontend for GDB?
 
@WesStark I don't like how Eloquent treats "models" for instance.
IE a table is a model. Always.
 
yeah orms are bad :P
 
Question...are repositories decoupled from persistence type?
 
persistence type?
 
@Allenph A model is a table.
 
4:29 AM
Should one repository be able to handle Postgres, MySQL, or memory.
@littlepootis No. It's not.
@WesStark Or should I have an individual repository for each?
 
in eloquent, I mean
 
What is the reason why PHP is used to build many popular sites, even if it’s considered to be a "bad" language by many developers?
 
@Allenph the mapper is a hidden dependency to the repo
$mapper = new PlayerMySQLMapper($dbal);
$repository = new PlayerRepository($mapper);
 
There are bad languages and then there are languages that nobody use.
 
@DamithRuwan It's because the barrier to entry is extremely low. It is both the reason so many websites are built with it AND the reason so many developers hate it. Low barrier to entry means more websites, and it also means a lot of bad code by beginners, such as myself.
 
4:31 AM
@DamithRuwan you just asked that a few minutes ago, please don't spam in here
 
but if you feel lazy you can have only Repository and have the sql queries in there rather than in the mapper. i don't do that...
 
@Allenph A table isn't a model, unless you associate to one.
 
Off Subject: "Hard Root Beer" my new favorite bitch beer. Murica'!
@littlepootis I understand that.
@WesStark What if memory is your persistence?
And will be the only possible form of persistence?
 
$mapper = new InMemoryMapper($storage /* e.g. an array-object */);
$repository = new PlayerRepository($mapper);
 
@WesStark So, a repository talks to a data mapper. The data mapper can be anything. I'm assuming data mappers share a common interface?
 
4:35 AM
obvs
 
@WesStark So...what's the difference between a data mapper and a repsoritory? :p
Seems like they would both have identical methods.
 
PlayerRepository::__construct(PlayerMapper $mapper);
class MysqlPlayerMapper implements PlayerMapper{}
class InMemoryPlayerMapper implements PlayerMapper{}
@Allenph i've explained it to you already :P the main purpose of repositories is preventing that the same object is fetched more than once from persistence
 
@WesStark I know you've said that a bunch of times...but it's hard to understand what that means pragmatically.
 
function getByID($id){
    if(!isset($this->cache[$id])){
       $this->cache[$id] = $this->mapper->getByID($id);
    }
    return $this->cache[$id];
}
just this.
 
So...really...it's the data mapper that does the heavy lifting.
And the repo just calls it.
 
4:39 AM
indeed
reason is that in your services you don't want to deal with two or more objects representing the same entity
in reality repositories can be really complex though... but you'll get there eventually
 
1) Something calls factory method on domain object.
2) Domain object class' factory method returns new domain object.
3) "Something" manipulates said new domain object. (Domain object has setters and getters for validation.)
4) Domain object tells repo to persist.
5) Repo tells domain mapper to persist.
?
Oops. Replace "domain object" with "aggregate."
 
$mapper = new PlayerMySQLMapper($playerFactory);
$mapper->fetchPlayer(22); // uses factory, returns a Player instance (which is the aggregate root)
since it's aggregate you need to hand the mapper any factory that is required to construct the aggregate

$mapper = new PlayerMySQLMapper($playerFactory, $contractDetailsFactory, $playerRoleFactory);
$mapper->fetchPlayer(22); // uses factory, returns a Player instance (which is the aggregate root), plus $player->role() that returns Role, etc.
but you don't need to abuse dependency injection, you can hardcode those factories in the mapper and be just fine
 
@WesStark I thought factories were methods?
Static methods.
 
no
$factory = function(){ return new User(...$argument); };

give_factory($factory);
The abstract factory pattern provides a way to encapsulate a group of individual factories that have a common theme without specifying their concrete classes. In normal usage, the client software creates a concrete implementation of the abstract factory and then uses the generic interface of the factory to create the concrete objects that are part of the theme. The client doesn't know (or care) which concrete objects it gets from each of these internal factories, since it uses only the generic interfaces of their products. This pattern separates the details of implementation of a set of objects...
 
posted on July 28, 2017

New Cyanide and Happiness Comic

 
4:52 AM
which is notably distinct from the factory method pattern
 
factory is the abstraction of the new operator, basically
 
@Allenph a couple classic books for some foundational stuff amazon.com/… amazon.com/Patterns-Enterprise-Application-Architecture-Martin/…
 
but forget about factories in the mapper @Allenph right now just think how to produce e.g. Player objects/aggregates from the Player data mapper
basically, pick the record and construct a Player out of it, then return it
you don't need more sophistication than that at this point
 
@PaulCrovella Thanks. I'll buy those in the morning.
@WesStark So, I have another question. Your answer reenforces it. I'm noticing the trend of instantiating objects that will only be used once per thread because "singletons are bad." It seems like every single high-level method (a controller action for instance) is going to end up with a lot of duplicated code and/or producing multiple copies of single use objects.
Every action call, for instance, must think about instantiating a repository...which calls a data mapper...which must be provided with a new factory instance.
 
@PaulCrovella I am really really sorry. Thanks for your advice.
 
@Trowski

Fixes issue when preparing different statements where the first 63 characters were identical (#1).

That sounds interesting. :D
 
@Allenph I was using the SQL as the statement name, but it truncates names after 63 characters, so Postgres would complain a statement with that name already existed.
I suspected just using the SQL as a name was a bad idea and it came up sooner than I thought. :-D
 
@Trowski I don't know Postgres...but that's definitely an interesting one!
 
@Allenph ok so, it's not wrong having one instance only or something, it's how singletons are executed that is wrong. it's not the class' business making sure that only one instance is instantiated. that's your job. you create one object only and you only use that, by passing it around.
that however doesn't mean you need to reuse as much as possible. if you had weak references and object pools all over the place you will only have wasted a lot of effort and have unnecessary complexity, because the cost of creating objects without doing anything with them is basically zero. you can create thousands of new DeepThought() objects. they won't waste resources unless you call ->answerToTheUltimateQuestionOfLifeTheUniverseAndEverything()
 
@WesStark So TECHNICALLY everything should be passed by reference...
But pragmatically...who gives a shit?
Is that what you're getting at?
 
5:15 AM
wat
objects are always passed by reference (it's an object reference, not a variable reference)
 
@WesStark It's strange. I have never met anyone in my (admittedly short) 4 year career who knows or cares as much as I do (including every single "senior engineer" I've ever been under) about design patterns...and yet when I talk in this room I feel like I can barely surpass Hello World.
 
the level in this room is pretty high indeed, and i'm pretty low too :P
 
And yet those senior guys make 30+ grand more than I do. :p
I shit you not I worked under a guy who didn't know how to use routing or really know MVC.
 
@WesStark they're passed by handle. use a different word, it helps distinguish it.
 
And he made 100k while I was making 70.
 
5:19 AM
@PaulCrovella yes should do that
 
morning all
 
@PaulCrovella When I define an object, the variable I get is actually an alias for the actual object. When I pass this variable as an argument, I get a copy of the handler (not reference) which references the actual object, right?
Wheras if I pass a string or something as an argument I get a copy of the string, unless I specify I want it as a reference. Correct?
@WesStark
 
objects are passed by handle, which is simply a number. the handle maps to the object, that is retrieved from a map when required, by handle
variable references are more like a tree. each variable reference can be defined to be "a mirror of" some other variable reference
 
@Allenph more or less, yeah. if you want to see a behavior difference between by ref and by handle see: 3v4l.org/DLCN2
 
got suddenly anxious because paul is checking all the crap i write, and expecting a "you are wrong"
paul is very severe :B
5
 
5:27 AM
:P
 
just trying to be helpful
:B
 
@WesStark I feel like there should be an example application SOMEHWERE that uses all this shit.
I 110% guarantee such a thing would reduce stupid questions.
I can't seem to find one, though.
 
@WesStark don't worry, i'm not paying that much attention
 
@WesStark The nearest I can find is this...
Also...that's a service CLASS not METHOD.
Which confuses me GREATLY.
 
@WesStark unsure
lost my glasses
 
5:34 AM
@Allenph domain service methods, which are usually grouped in a class :B
 
@JayIsTooCommon it's your fault ... obviously ...
 
aka, services
it's a crap name but it's what everybody uses
 
@JoeWatkins again ? :-p
morning Joe
 
I can't understand why websites that get a lot of visitors don't implement SSL certificates :|
 
yeah, but I know they are in the house this time
@Alesana people are idiots
 
5:36 AM
@JoeWatkins Still want to meet up?
What's does next week look like?
 
what, what's happening ?
I have no idea what you are talking about :s
 
Morning
 
yo ekin
 
o/
 
5:40 AM
o/
 
no no no
 
lmao
 
we'll start again
yo ekin
 
\o
 
5:41 AM
damn you paul
 
@JoeWatkins I 100% thought you were someone else. For some reason I remembered your username. My bad.
 
:D
 
@Allenph oh gooood, I'm not supposed to remember what you're talking about ...
 
Shit. I can't remember that guys username.
I know he was smarter than me and I wanted to bug the shit out of him with stupid questions.
 
@Allenph @LeviMorrison
 
5:45 AM
@WesStark WAIT! That handler thing means...the repo handles me not querying the database a billion times. The fact that I'm passing that object by handler means I can get an object from the repo, mess with it...and it's reflected anywhere I mess with it further down the line?!
@Alesana How could you possibly remember that?! xD
 
Haha I didn't I just looked in your chat history
Oh that sounds weird now
 
@Alesana I must not know how to use this chat effectively.
That would take several eternities.
 
Haha you can search using keywords
 
mornin all
 
5:51 AM
I saw new PHPStorm has object type hints as a differentiator on versions list, Yay :)
o/
@JayIsTooCommon I need time for this but I will do it
 
@Allenph by handle
because you "grab" it
 
oh I see why you were confused
Jun 30 at 16:46, by Joe Watkins
user image
 
i don't know why you started talking of object handles and variable references
 
I wonder how many more dick pics @PeeHaa is getting with his DMs open
 
@WesStark

- Repositories act as in-memory DB caches.
- Data Mappers share a common interface to ensure the repository can talk to them. They abstract the persistence.
- Repos are for aggregates. Which may contain several other domain objects. Each with their own properties and methods.
- Services are able to mess with objects which have not been passsed to them, because they can ask the Repo and get a handler.
Question:

When should one NOT put methods on an object, and instead put them in a dedicated service class?
@JoeWatkins This has been a cat-astrophe.
@PaulCrovella At least one. o.O
 

« first day (2477 days earlier)      last day (2461 days later) »