Account Options

  1. Sign in
The old Google Groups will be going away soon, but your browser is incompatible with the new version.
Google Groups Home
« Groups Home
Namespacing Joomla Platform code for backwards/forward compatibility
There are currently too many topics in this group that display first. To make this topic appear first, remove this option from another topic.
There was an error processing your request. Please try again.
flag
  5 messages - Collapse all  -  Translate all to Translated (View all originals)
The group you are posting to is a Usenet group. Messages posted to this group will make your email address visible to anyone on the Internet.
Your reply message has not been sent.
Your post was successful
 
From:
To:
Cc:
Followup To:
Add Cc | Add Followup-to | Edit Subject
Subject:
Validation:
For verification purposes please type the characters you see in the picture below or the numbers you hear by clicking the accessibility icon. Listen and type the numbers you hear
 
garyamort  
View profile  
 More options Jun 21 2012, 12:42 pm
From: garyamort <garyam...@gmail.com>
Date: Thu, 21 Jun 2012 09:42:00 -0700 (PDT)
Subject: Namespacing Joomla Platform code for backwards/forward compatibility

I was wondering when Joomla is going to advance to require PHP 5.3 only and
if that can also include adding namespaces.

For example, all core code could be namespaced as Joomla\Platform
All cms code could be namespaced as Joomla\CMS

For backwards/forwards compatibility, aliases should be used:
use Joomla\Platform as J;
use Joomla\CMS as J\C;

So, for example:
$controller = JController::getInstance('Content');

Would become:
use Joomla\Platform as J;
$controller = J\JController::getInstance('Content');

Then for compatibility, some simple find/replaces on namespaced calls are
all that is needed:
libraries/compat/joomla/v12.4
Change their namespace declarations:
namespace Joomla\Platform;
use Joomla\Platform as J;
becomes
namespace Joomla\Platform\12.4;
use Joomla\Platform as J;

Now if an app for the CMS needs the 12.4 Controller model, it can use
either:
use Joomla\Platform\v12.4 as J;
or it could use
use Joomla\Platform\v12.4\JController as JController;  

Just the JController for 12.4 is used, all other classes will come from the
current platform code even in JController since it always calls them as
J\JLog

Better yet, if there is a small subset of classes which someone might need
for compatibility issues,
only those can be stuck in libraries/compat/joomla/v12.4
For example, if ONLY the MVC classes are needed, then stick only their
files in the compat folder.  A find/replace on those files for
J\JController, J\JModel, and J\JView to make them become JController,
JModel, JView [and hence local classes]

So, things like
public function authorize($task)
{
// Deprecation warning.
J\JLog::add('JController::authorize() is deprecated.', JLog::WARNING,
'deprecated');

$this->authorise($task);

}

Will call the default Joomla\Platform namespace wheras
protected function createModel($name, $prefix = '', $config = array())
{
// Clean the model name
$modelName = preg_replace('/[^A-Z0-9_]/i', '', $name);
$classPrefix = preg_replace('/[^A-Z0-9_]/i', '', $prefix);

$result = JModel::getInstance($modelName, $classPrefix, $config);

return $result;

}

Since the find/replace updated J\JModel to JModel it will be from the local
space.

It is also great in that it allows both forwards and backwards
compatibility.   Hypothetical:
Joomla CMS v5 is running on Joomla Platform v15.3
A lot of legacy extensions are still using the MVC framework of Joomla
Platform 14.4
A lot of useful MVC features are in Joomla Platform 16.1

By containing directories with the MVC framework under namespaces
Joomla\Platform\v14.4
and
Joomla\Platform\v16.1

Legacy extensions may just need to change one line of code:
use Joomla\Platform as J;  
to
use Joomla\Platform\v14.4 as J;

And completely new extensions could be forward looking and use the new
models with
use Joomla\Platform\v16.1 as J;

Alternatively, going by the PHP Framework Interoperability Group standards:
https://github.com/php-fig/fig-standards/blob/master/accepted/PSR-0.md

It can be somewhat cleaner to say that the Joomla Framework is part of the
global application space and only apply namespaces for compatability.

IE JController remains in the global namespace
For MVC compatibility:
Joomla\Platform\v14.4\JController
Update all calls to classes starting with J to be \J, ie JLog becomes \JLog
Update all calls to MVC classes to remove the slash, so \JModel becomes
JModel

This is somewhat more work for the compatibility libraries, but then it's
also somewhat proper to make someone needing a different version of Joomla
core libraries do the work and keep things simple for the core code.


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Elin Waring  
View profile  
 More options Jun 21 2012, 5:10 pm
From: Elin Waring <elin.war...@gmail.com>
Date: Thu, 21 Jun 2012 14:10:47 -0700 (PDT)
Local: Thurs, Jun 21 2012 5:10 pm
Subject: Re: Namespacing Joomla Platform code for backwards/forward compatibility

The platform already requires 5.3 and that is the minimum which has been
announced for CMS 3.0.  We are using J for both the CMS and Platform which
works out well for developers and makes it possible to continue the easy
movement of platform classes from Platform to Legacy to CMS .. and who
knows maybe from CMS to Platform at some point.

Elin


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Florian Voutzinos  
View profile  
 More options Jul 23 2012, 4:07 am
From: Florian Voutzinos <voutzinos.flor...@gmail.com>
Date: Mon, 23 Jul 2012 01:07:00 -0700 (PDT)
Subject: Re: Namespacing Joomla Platform code for backwards/forward compatibility

I think we need to drop the J prefix if Joomla is namespaced, because
mixing both is bad (the goal of namespaces is also to avoid prefixes).

People won't have to change any call :

use Joomla\Factory as JFactory;

$app = JFactory::getApplication()...

It is even possible to parse their extension files and generate the correct
use to place in the file headers, so they won't have to modify any call.

Le jeudi 21 juin 2012 18:42:00 UTC+2, garyamort a écrit :


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Chad Windnagle  
View profile  
 More options Jul 23 2012, 10:00 am
From: Chad Windnagle <drmmr...@gmail.com>
Date: Mon, 23 Jul 2012 10:00:37 -0400
Local: Mon, Jul 23 2012 10:00 am
Subject: Re: [jplatform] Re: Namespacing Joomla Platform code for backwards/forward compatibility

> I was wondering when Joomla is going to advance to require PHP 5.3 only
> and if that can also include adding namespaces.

The platform already requires PHP 5.3, and it's been proposed that Joomla
3.0 will also require PHP 5.3.1
http://www.joomla.org/technical-requirements.html

Regards,
Chad Windnagle
Fight SOPA <https://www.google.com/landing/takeaction/>

On Mon, Jul 23, 2012 at 4:07 AM, Florian Voutzinos <


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Andrew Eddie  
View profile  
 More options Jul 23 2012, 2:10 pm
From: Andrew Eddie <mambob...@gmail.com>
Date: Mon, 23 Jul 2012 11:10:10 -0700
Local: Mon, Jul 23 2012 2:10 pm
Subject: Re: [jplatform] Namespacing Joomla Platform code for backwards/forward compatibility
On 21 June 2012 09:42, garyamort <garyam...@gmail.com> wrote:

> I was wondering when Joomla is going to advance to require PHP 5.3 only and
> if that can also include adding namespaces.

We can address namespacing when the Platform is completely
auto-loadable.  Trying to do it in bits and pieces is probably not the
best way to approach it.

Regards,
Andrew Eddie
http://learn.theartofjoomla.com - training videos for Joomla developers


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
End of messages
« Back to Discussions « Newer topic     Older topic »