Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:97547 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 7013 invoked from network); 6 Jan 2017 22:50:01 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 6 Jan 2017 22:50:01 -0000 Authentication-Results: pb1.pair.com smtp.mail=pmjones88@gmail.com; spf=pass; sender-id=pass Authentication-Results: pb1.pair.com header.from=pmjones88@gmail.com; sender-id=pass Received-SPF: pass (pb1.pair.com: domain gmail.com designates 209.85.161.172 as permitted sender) X-PHP-List-Original-Sender: pmjones88@gmail.com X-Host-Fingerprint: 209.85.161.172 mail-yw0-f172.google.com Received: from [209.85.161.172] ([209.85.161.172:32962] helo=mail-yw0-f172.google.com) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id A8/5C-23307-71F10785 for ; Fri, 06 Jan 2017 17:49:59 -0500 Received: by mail-yw0-f172.google.com with SMTP id r204so381946312ywb.0 for ; Fri, 06 Jan 2017 14:49:59 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:content-transfer-encoding:mime-version:subject:message-id:date :to; bh=W9BLxgl8RaSuMG4ld2gvLUL5dn1H4MmrfTYFcCH4LgU=; b=Mj8o1GVTtMJ2Xo3yLEUm4aML08h9jZsHoXSY/QndfSjGvkfQPx1t3f1HHyo7YOm8y2 Tx/OgvEt/YqqXWD0AUyz4XU8oITiId2f6cb3gWj2jHAOvjVU7GfrVmz0cPyIZN8aTUha R5vTj9rqSgdn3B89/BBfaYLe5I/AfMJPh1fJsKPvLZRO/eU5dpFKT1PfOptZESZ2Gjzv ueJejmzzSJhkMpvlhghdXVv8DUEM/YMA8fnIVGTug0lMw1OwIoBb2jViZX41OUFl42/D FtEzyDyLZkh9I4FctXUbe/t3OBt+PaypYStzR84OriqoqG2gnOT8iPmNx5j+8eqjs02j B7pw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:content-transfer-encoding:mime-version :subject:message-id:date:to; bh=W9BLxgl8RaSuMG4ld2gvLUL5dn1H4MmrfTYFcCH4LgU=; b=RRvgZ/ETqVTYMBTO17B+JIejnYtqVklKj53MPmaTRBIKwo5HMrOKtYnwaVFxJw6Fyp j0E/G53KunA1SfMOfgbC7oPoGyG/7cAAwG0hgmfcJFsokk4M2kmq1n/2P9r3AIrDgknt Y9c8bcKY0mv7M6R87xp50NAW2+b3bc3gFhEHG6k4D4JrAYBofVZtfICnNzvk2nP4wqQ/ PGCiKjyiW7BRLntVlmFbqSd5tCjqCGn5RRuW0XnCKenEfk+ThK8WCyA04bWDitMI74LN LLSYr+rdN2fuAZM0A7VEyT+BtPvktV1mZI4za5/XlgGlw2ifJLs8k6UsFsylghQsT5xT sVSw== X-Gm-Message-State: AIkVDXIGxhdJbOmx6jKa04mx1maVaw1aMkfOoFXrHpbEP3yTUFatYDpBeUpTMhSFjBUa9g== X-Received: by 10.13.242.71 with SMTP id b68mr73069999ywf.49.1483742996386; Fri, 06 Jan 2017 14:49:56 -0800 (PST) Received: from samurai.attlocal.net (107-223-29-56.lightspeed.nsvltn.sbcglobal.net. [107.223.29.56]) by smtp.gmail.com with ESMTPSA id q7sm27166616ywa.36.2017.01.06.14.49.55 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Fri, 06 Jan 2017 14:49:55 -0800 (PST) Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: quoted-printable Mime-Version: 1.0 (Mac OS X Mail 10.2 \(3259\)) Message-ID: Date: Fri, 6 Jan 2017 16:49:54 -0600 To: PHP Internals List X-Mailer: Apple Mail (2.3259) Subject: [RFC][Discussion] ServerRequest and ServerResponse objects From: pmjones88@gmail.com (Paul Jones) (This is a re-send, on a new thread, of the message originally posted at = with some minor edits. The = original was apparently not delivered to the entire list.) ---------------------------------------- Hi all, I have prepared an RFC on server-side request and response objects: https://wiki.php.net/rfc/request_response This extension provides server-side request and response objects for = PHP. These are not HTTP message objects proper. They are more like = wrappers for existing global PHP variables and functions, with some = limited additional convenience functionality. This extension defines two classes in the global namespace: - ServerRequest, composed of read-only copies of PHP superglobals and = some other commonly-used values, with methods for adding = application-specific request information in immutable fashion. - ServerResponse, essentially a wrapper around (and buffer for) = response-related PHP functions, with some additional convenience = methods, and self-sending capability. The extension is available as a PECL package for installation and = testing at: https://pecl.php.net/package/request Source and documentation are at: https://gitlab.com/pmjones/ext-request I want to point out that I am not the author of the C code for this = extension; John Boehr has done the work there, and I appreciate it a = great deal. When I originally raised this topic in September, there were some = questions left unanswered from Rowan Collins; I'll try to address them = below. * * * Rowan asked why this would need to be implemented to as an extension or = built into core: "Does it provide functionality that is hard to = implement in a userland library?" It does. Among other things, making public read-only properties is = difficult and hackish in userland. Making them remain read-only when a = parent class is extended is (as far as I can tell) impossible. Both of = those aspects figure prominently in ServerRequest. * * * Rowan also asked: "You mention that it is not just an HTTP wrapper, but = although you mention researching other frameworks, I can't see any = reference to PSR-7. What do you see as the relationship between your = proposal and that standardisation effort?" While PSR-7 is not a framework, I get your point. ;-) For what it's = worth, I was a sponsor on that proposal, so I'm relatively familiar with = its history and purpose. I see the relationship as complementary. Those who want something that = matches a formal HTTP model more closely can use one of the two popular = PSR-7 implementations, or write their own. Or they can use `pecl_http`, = for that matter, which I think PSR-7 ends up mimicking in significant = ways. Those who want something that more closely matches core PHP = functionality, or the way-of-working presented by many extant frameworks = and libraries, might find this extension more in line with their needs. = I certainly do. * * * Finally, Rowan brought this up: "Why is [ServerRequest] property-only, = but [ServerResponse] method-only? The asymmetry feels awkward to me." I get why that would be. It's really an outgrowth of the asymmetry that = already exists in PHP: $_GET, $_POST, et al. are properties representing = the request, whereas header(), setcookie(), et al. are all functions for = sending a response. Having said that, practical use of ServerRequest the intervening time = has given rise to some methods for application-related convenience. The = methods withUrl(), withInput(), and the various withParams() methods = allow changing of immutable public properties on a clone of = ServerRequest. (As a side note, immutability here is relatively strict. ServerRequest = allows only null, scalar, and array values in these cases, and = recursively checks that arrays themselves have only null, scalar, and = array values.) * * * This (re-)opens the two-week discussion period, though I expect it may = go on for longer than that. As this is a language change, a supermajority vote is needed to pass. Thanks in advance for your questions and criticism. --=20 Paul M. Jones pmjones88@gmail.com http://paul-m-jones.com Modernizing Legacy Applications in PHP https://leanpub.com/mlaphp Solving the N+1 Problem in PHP https://leanpub.com/sn1php