Namespace support

19 views
Skip to first unread message

Simon J Welsh

unread,
Dec 12, 2010, 4:20:31 PM12/12/10
to SilverStripe Development
I'm breaking this out into its own thread, rather than letting it continue in the 3.0 thread.

I have a working patch for adding some basic namespace support into sapphire. Currently it only supports namespaced classes, though adding it for interfaces will be a very minor adaption to the class code. I just wanted to get some testing in before I started duplicating code.

It currently supports only one namespace in a file, using the namespace name; format (not namespace name { code }). You can use namespaced classes anywhere you would use ones in the global space, so long as you provide the correct path. This includes DataObject::get() calls and Director rules.

Controllers will fall back to the namespace-less class name when looking for templates.

I have not tested this with PHP <5.3 yet, nor have I tested the CMS (the project I want namespaces for doesn't use it).

I am thinking of replacing the \ in class names when looking for template files (Windows probably wont like them) and in table names (MySQL seems to handle the \ fine, but others may not) with some other character. Something like a plus or hyphen (can't use an underscore as there could be naming conflicts).

The current state of the patch is available at http://s.geek.nz/A
---
Simon Welsh
Admin of http://simon.geek.nz/

Who said Microsoft never created a bug-free program? The blue screen never, ever crashes!

http://www.thinkgeek.com/brain/gimme.cgi?wid=81d520e5e

Simon

unread,
Dec 12, 2010, 4:34:17 PM12/12/10
to SilverStripe Core Development
Forgot that I had already committed some hacks in core/Core.php. The
diff file should now be able to be applied to branches/2.4 cleanly.

On Dec 13, 10:20 am, Simon J Welsh <welsh.si...@gmail.com> wrote:
> I'm breaking this out into its own thread, rather than letting it continue in the 3.0 thread.
>
> I have a working patch for adding some basic namespace support into sapphire. Currently it only supports namespaced classes, though adding it for interfaces will be a very minor adaption to the class code. I just wanted to get some testing in before I started duplicating code.
>
> It currently supports only one namespace in a file, using the namespace name; format (not namespace name { code }). You can use namespaced classes anywhere you would use ones in the global space, so long as you provide the correct path. This includes DataObject::get() calls and Director rules.
>
> Controllers will fall back to the namespace-less class name when looking for templates.
>
> I have not tested this with PHP <5.3 yet, nor have I tested the CMS (the project I want namespaces for doesn't use it).
>
> I am thinking of replacing the \ in class names when looking for template files (Windows probably wont like them) and in table names (MySQL seems to handle the \ fine, but others may not) with some other character. Something like a plus or hyphen (can't use an underscore as there could be naming conflicts).
>
> The current state of the patch is available athttp://s.geek.nz/A
> ---
> Simon Welsh
> Admin ofhttp://simon.geek.nz/
Reply all
Reply to author
Forward
0 new messages