« first day (593 days earlier)      last day (4369 days later) » 

user895378
9:00 PM
@tereško the response object is injected into the controller constructor and, once populated, is returned by the controller method
 
@rdlowrey getAllHeaders as well.
 
And when you join a project where the DB has been misengineered you have very little scope to change it to something more sensible :(
 
@rdlowrey , if it was injected , you do not need to return it =P .. you are doing it wrong
 
@LeviMorrison that looks like a HTTP interface, not a generic response interface. A generic response could be some stream with additional metadata.
 
@hakre Well, it is an Http\Response.
 
9:02 PM
oh ;)
 
user895378
@tereško good point :)
 
user895378
hadn't even occurred to me that I already have the response object :)
 
@JavascriptGeek Normally apache + static HTML / CSS / JS have that.
 
@tereško I don't think it should be injected, personally.
 
user895378
@LeviMorrison Why not?
 
9:03 PM
@LeviMorrison , then how will you get it ?
 
@hakre JSS?
 
user895378
injection > new
 
@NikiC JavaScriptScripts ;)
 
using $response = new Response in a controller @LeviMorrison ? .. that would imply tight coupling to the name of class
 
@hakre Ah, I thought it was some mix of JS and CSS ^^
 
9:04 PM
@NikiC java scripted styles.
 
Like a new framework where you write your CSS in jQuery instead!
 
@tereško ResponseFactory->create() perhaps.
 
overkill much
what additionally the factory does in this case ?
 
user895378
@LeviMorrison Why ask for a factory if there's only one kind of response object with no constructor?
 
Hate EAV tables. Hate CSV lists in columns, and HATE serialized data in columns!
 
9:05 PM
@LeviMorrison , ad in this case you will have to inject the factory
@li
 
There seem to be two good code writing principles at odds here. You shouldn't use parameters to return things, but at the same time I shouldn't couple it by using new. That's my point. Of course, you can resolve it by pretending that the controller doesn't return anything, but it does modify it, and thus it shouldn't be a parameter.
 
Seriously, one of the projects I had at work this week was changing the alt of an image stored in the database. Sounds easy enough, except the image was stored as a serialized array. Even being diplomatic I just couldn't hold back on letting my boss know what a dumb fuck he was for that design choice. The hoops I had to jump through to update the data!
 
all data you store is serialized, only the level of normalization changes.
 
@LeviMorrison , that first is one of main rules in procedural programming
 
however, was that a serialized array or even more akward?
 
user895378
9:08 PM
The controller class asks for a Response in its constructor. The relevant controller method adds headers and body to the response object. Afterwards, we have a fully populated Response object sitting around in the global namespace waiting to be output/cached/whatever.
 
user895378
I wasn't thinking before when I said the controller method needed to return the Response after it was populated.
 
@rdlowrey . . . and that doesn't seem wrong to you?
 
@LeviMorrison , in real life , you pick up a thing , you fiddle with it , and you put it down
the thing has changed
you did not discourage the thing , only relinquished the control over it
 
user895378
@LeviMorrison If you avoid all modification of objects inside other objects you have to stop passing objects by reference entirely.
 
user895378
well, basically
 
9:11 PM
Question: Why does a controller needs to add headers?
 
@rdlowrey And you do realize that there are some languages that are built on that premise, right?
 
@hakre , because they are still working with channel's April version of "understand the MVC"
 
@rdlowrey By the way, the view should probably do that, not the controller.
 
user895378
@LeviMorrison You're right there -- I misspoke. The view that's injected into the controller does do the header stuff.
 
I'll think about what everyone said and do some more work. Maybe something will click in my head.
 
user895378
9:15 PM
@LeviMorrison Same ... within 24 hours or so I'll have a working version pushed up, which will make the argument less academic. We can look at actual code and say, "let's change how this works."
 
@rdlowrey method hasBeenSent?
 
wasSent() would be better
 
user895378
@LeviMorrison That's a good idea ... though I prefer wasSent() as well.
 
@tereško true.
 
user895378
9:26 PM
@LeviMorrison It occurred to me that the way I have it set up, it's actually entirely up to the user whether you supply the Response as a dependency in the constructor or as a parameter to the relevant controller method. Also, I realized that there's no need to expect controller methods to return the populated Response object either, because the Response object itself will broadcast notifications when things happen (e.g. on Response::render) so that listeners can do whatever they want.
 
@rdlowrey You might have to implement the broadcasting part.
 
user895378
@LeviMorrison Oh, yeah, that's no problem.
 
    function getHeader($header) {
        if (!$this->hasHeader($header)) {
            throw RuntimeException();
        }

        return $this->header[$header];
    }
What exception to throw?
 
user895378
I would throw an OutOfBoundsException I think
 
Ick, I wouldn't.
 
user895378
9:28 PM
hehe
 
where to put this code pokit.org/get/img/e520efcc26aaf77c844b44fde9f7eeda.png bootstrap, static class, or something else? needs to be accessed "globally"...
 
Whatever it is, it's a RuntimeException, so I can at least throw that for now.
 
user895378
To me, a DomainException seems more appropriate when you have a fixed set of possible options known ahead of time ...
 
user895378
but I always agonize over which specific SPL exception to throw ...
 
@webarto `trashcan? ;)
 
9:30 PM
@rdlowrey We all do. They could have been done much better.
 
seems legit
 
@LeviMorrison Don't throw an exception, return a special case header, the not-set header.
 
@webarto , the function ( if part of class ) gets accessed statically too
oh .. wait .. nevermind
 
yes, no such thing as static classes
 
@hakre I'd say throw something because we have the ability to see if it exists. See what I mean?
 
user895378
9:30 PM
@LeviMorrison or you could just return NULL as you'll never have a header whose value is NULL ...
 
@webarto , thats procedural programing to begin with , so i would blame it only for method chaining , and lack of braces brackets the "{}" thing
 
@LeviMorrison you don't look for exceptions.
 
@hakre I understand the philosophy. However, if I call getHeader on something that means it SHOULD be there. And when it comes down to practicality, the best way to handle it is to throw an exception that makes me handle it.
 
Practically, this is a proven concept:
    function getHeader($header, $default = NULL) {
        if (!$this->hasHeader($header)) {
            return $default;
        }

        return $this->header[$header];
    }
 
@hakre That is very, very ugly.
Effective perhaps.
 
9:33 PM
if you consider it to return string types only, it isn't.
At least not very.
If you consider it to return header objects, I already have done a suggestion.
 
@tereško thanks for response, function needs to be available so designer fags can use it in layout... and they consider HTML/CSS programming... yes, I don't write {} for one liners... do you have some good link for syntax standard?
 
i think Levi just recently learned about exceptions .. and now everything looks like a nail for the shiny new hammer
 
user895378
IMHO ... if you have a well-constructed universal exception handling mechanism, throwing exceptions for things like that makes debugging easier.
 
user895378
But it's mostly a matter of preference.
 
Yeah I once signalled HTTP response codes by throwing exceptions. But luckly I didn't enforced that concept more and dropped it.
Always take care of layered approaches. The one layer should only know the one above and below.
If you want to come to good abstractions, the layers should not leak much.
 
9:36 PM
@tereško Not at all. I just think that a Header object or a HeaderValue object are overkill. Let's be honest: an exception makes you fix the problem as long as you don't just catch all and do nothing.
 
Exceptions can be such a leakage between layers.
@LeviMorrison Which problem?
 
@hakre , thats a chicken-egg problem
 
@tereško Not this time.
 
@hakre Getting a header that doesn't exist. Maybe you don't think that's an exceptional circumstance, but I absolutely do.
@rdlowrey By the way, I disagree with:
/**
 * Retrieves the StdRequest URI
 *
 * Consider the following request:
 * mysite.com/users/user25?showFriends=true
 *
 * The getUri method should return: `/users/user25`
 */
 
user895378
@LeviMorrison I disagree with your disagreement :)
 
9:39 PM
A url class might be in order, but at least for the moment this class isn't going to be much of an abstraction from a real HTTP request.
 
user895378
At least in a RESTful context, url parameters are modifiers ... they have nothing to do with the core resource
 
user895378
The URI without parameters is the resource. Parameters are options.
 
@LeviMorrison A header that doesn't exist in HTTP has a default value. You need to look into the specs and return the default value instead if you really want to do this correctly.
 
if you want to learn proper PHP, you should read transcripts of this chat everyday...
 
@LeviMorrison At least if you actually care about doing this correctly.
 
9:41 PM
@hakre I'll check the specs, but I'm pretty sure that there are defaults on a per header basis, not a general header default.
 
@LeviMorrison There is no header without a name. You should throw exceptions if you pass a header name in there that is invalid. That you can do.
 
user895378
@hakre I tend towards exceptions, personally, and would also throw one in that case. I think asking for a header that doesn't exist represents an error in your program logic.
 
user895378
Of course, at this point I think I've lost track of the original context anyway :)
 
I wish php could do type checking for string.
 
@LeviMorrison It can, you only need to install the extension. php.net/manual/en/book.spl-types.php
 
9:44 PM
@hakre I may choose to eventually
 
user895378
> This extension is EXPERIMENTAL. The behaviour of this extension including the names of its functions and any other documentation surrounding this extension may change without notice in a future release of PHP. This extension should be used at your own risk.
 
user895378
I know it's just there to scare away n00bs, but still ...
 
user895378
I'm not crazy about developing around those kinds of features.
 
@hakre
    /**
     * @param $header
     * @return string
     * @throws RuntimeException
     * @todo Figure out the best exception to throw. Perhaps one isn't needed.
     */
    function getHeader($header) {
        if (!$this->hasHeader($header)) {
            throw new RuntimeException();
        }

        return $this->headers[$header];
    }
 
user895378
Anyway, fun time over. @LeviMorrison I actually will be back here later writing code (unlike last night) for talk/comments/discussion/questions.
 
9:48 PM
@rdlowrey Enjoy.
 
user895378
adios, bro-tastic brogrammer dudes.
 
@rdlowrey I'm going to read some HTTP specs. I'll be more sure on my vernacular next time we speak.
 
10:06 PM
@hakre LOL
 
stackoverflow.com/questions/10842028/… he has no idea, but he knows it's simple
 
10:39 PM
@rdlowrey I made Request, Response, StdRequest and StdResponse. They follow the RFC 2616 loosely and aren't abstracted much from it. We'll want to add things later, I am sure. Also, we need to make a class that will convert the current/incoming request into a Request object. I am sure I broke a bunch of things. I deleted and renamed too many things to not have broke something.
 
10:54 PM
(Side note: break is one of the words I am never confident in its usage for different tenses)
 
user895378
11:34 PM
@LeviMorrison lol at your grammatical reflections on the different conjugations of "break" ... None of that really matters because I think break would've meant it was fully functional before ... which it wasn't :)
 

« first day (593 days earlier)      last day (4369 days later) »