Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:34209 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 32116 invoked by uid 1010); 21 Dec 2007 20:30:38 -0000 Delivered-To: ezmlm-scan-internals@lists.php.net Delivered-To: ezmlm-internals@lists.php.net Received: (qmail 32091 invoked from network); 21 Dec 2007 20:30:38 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 21 Dec 2007 20:30:38 -0000 Authentication-Results: pb1.pair.com header.from=malterisio777@gmail.com; sender-id=pass; domainkeys=bad Authentication-Results: pb1.pair.com smtp.mail=malterisio777@gmail.com; spf=pass; sender-id=pass Received-SPF: pass (pb1.pair.com: domain gmail.com designates 64.233.162.225 as permitted sender) DomainKey-Status: bad X-DomainKeys: Ecelerity dk_validate implementing draft-delany-domainkeys-base-01 X-PHP-List-Original-Sender: malterisio777@gmail.com X-Host-Fingerprint: 64.233.162.225 nz-out-0506.google.com Received: from [64.233.162.225] ([64.233.162.225:37140] helo=nz-out-0506.google.com) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id 2A/A0-24311-E522C674 for ; Fri, 21 Dec 2007 15:30:32 -0500 Received: by nz-out-0506.google.com with SMTP id x7so253911nzc.38 for ; Fri, 21 Dec 2007 12:30:07 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma; h=domainkey-signature:received:received:message-id:date:from:to:subject:mime-version:content-type; bh=JD18FEUNoamG4jsNGrwmufutWDD3e0y3FBhPiOs+PTQ=; b=pyNphWdQueJ5WGqbq6sP2IRqSBbE17enaDxb6cMCJODLx3mwjGTSGHSY5cFIOXR8zsehl7TYmwcMO86T40tYdIXE3ytbrOYLSqsuTxaIFtK254mwi59HHVEMHIUmyvCC/jJVgp6FqaoLDulsgHBSa4JTX7YTQ/z2XlVm7CuhcwU= DomainKey-Signature: a=rsa-sha1; c=nofws; d=gmail.com; s=gamma; h=message-id:date:from:to:subject:mime-version:content-type; b=etjO/tSQrKxlP2aXllkPcPzi4ysBUKBeJ5YB3vZVTY/jmXzjca73vByRHk0Ui9/XbdPsTpSvqnx56U2lfpIi9gOXgxse8Q5vzmhm6Of3I1IKopRrbqZS0UFpbWS5y5y5g/SFpucmMPNyUSrhE6Ds2Df3+u6J5eX/8f2d1DyZ8z4= Received: by 10.142.217.17 with SMTP id p17mr919094wfg.139.1198269007433; Fri, 21 Dec 2007 12:30:07 -0800 (PST) Received: by 10.142.157.9 with HTTP; Fri, 21 Dec 2007 12:30:07 -0800 (PST) Message-ID: <52dbac0f0712211230v17c0762cs4b9e37db29e2bc34@mail.gmail.com> Date: Fri, 21 Dec 2007 17:30:07 -0300 To: "PHP Developers Mailing List" MIME-Version: 1.0 Content-Type: multipart/alternative; boundary="----=_Part_1693_12756567.1198269007383" Subject: Refactoring code for namespaces appliance From: malterisio777@gmail.com ("Martin Alterisio") ------=_Part_1693_12756567.1198269007383 Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: 7bit Content-Disposition: inline Has anyone tried refactoring a "real world" application/library to use namespaces? I've been pondering about how to algorithmically/mechanically prepare a non namespaced code for namespaces appliance. This would be a first step which will just prepare the code for namespaces in a safe way, but not to profit from aliases created by use. The latest will have to be implemented manually (IMHO). I've come up with the following, for an organization model of a class per file. Please review. 1) find the class definition and reduce the class name to namespace/class 2) add namespace declaration on top of file 3) replace class name in definition with short name 4) find all function calls (not method calls) which are not keywords (array, isset, unset, list, etc) and prefix them with :: 5) find all class names (static method calls (no self:: nor parent::), new, catch, type hints, instanceof, extends, implements) and: 5a) replace separator used (possibly: _) with namespace separator (::) 5b) IF the class has no namespace (ie global namespace) prefix the class name with :: 5c) IF the namespace of the class starts with the same namespace found in (1), remove it or prefix it with namespace:: (although this is not necessary) 6) find static method calls with variables used as class name, and mark them for user handled refactoring 7) find internal functions that use callables (call_user_func, array_map, array_filter, etc) and mark them for user handled refactoring Later on, a methodical way of adding use statements for reducing the class names used, can be implemented. Although this might be more complicate than it seems if the method has to be careful to avoid creating possible name clashes. If anyone has a comment on this, I'll be more than grateful if you share. Best Regards, Martin Alterisio ------=_Part_1693_12756567.1198269007383--