@sequence ---
@title org.netfrag.yakka - ApiDoc available - powered by phpDocumentor
@file C:\home\amo\develop\netfrag.org\joko\doc\twingled\SampleNewsPosts\Re - Namespaces in PHP.twingle
@link http://grasshopper.netfrag.org/c/home/amo/develop/netfrag.org/joko/doc/twingled/SampleNewsPosts/Re - Namespaces in PHP.twingle
@link http://www.netfrag.org/webnews/article.php?id=15&group=nfo.dev.php
@link http://news.netfrag.org/nfo.dev.php/id/15/

Hey bareface,

David Bareface wrote:
> [...]
> I checked out your approach for this issue and it's quite interesting. imho
> this is a good way to avoid class redeclarations.
> maybe syntaxing could be better. use a static class to get instances
> maybe something like this:
>
> /* just pseudo-code */
>
> class php {
>     function getInstance($class) {
>         global $uns;
>         $class = $uns."_".$class;
>         return new $class;
>     }
>
>     function useNamespace($ns) {
>         global $uns;
>         $uns = $ns;
>     }
> }
>
> php::useNamespace("Application");
> $config = php::getInstance("Config");
>
> cu
> bare

Thanksalot for this!

Yesterday I tried to mungle some of already 
existing code from org.netfrag.flib towards 
your proposal - what came out was:


--- The php and the Exporter classes.

syntaxing inspired by bareface: (e.g.)

    php::useNamespace("Data::Driver");
    $config = php::getInstance("Proxy");


@sequence
@title What did we do?
@is-a RefactoringProcess

What did we do?

We tried to refactor some code to a newly 
introduced class named 'php':

@subsequence
@title What do we get?
@is-a RefactoringTarget
@class php


@subsequence
@title What did we have?
@is-a RefactoringSource

What did we have?

Some code living at org.netfrag.flib:

@package org.netfrag.flib
@file flib/utils/helper.php
@file flib/utils/shortcuts.php
@function loadModule
@function mkObject

Some code living at org.netfrag.glib:

@package org.netfrag.glib
@subpackage DesignPattern
@file ...rag.glib/DesignPattern/Bridge.php
@component DesignPattern::Bridge
@class DesignPattern_Bridge
@methods '_mkInstance' and '_mkEmbeddedObjects' 



@subsequence
@title What do we have *now*?
@is-a RefactoringTarget
@class php Exporter


What do we have *now*?

Some code living at org.netfrag.glib:

@file ...rag.glib/php_extensions.php
@component php_extensions
@class php
@methods loadModule, mkInstance, mkComponent

@file ...rag.glib/Exporter.php
@component Exporter
@class Exporter

The Exporter is used to alias php::mkComponent
to the former global function mkObject.

@subsequence
@synopsis The classes can be used this way:

<code>

  php::loadModule('my::Module');

  $comp = php::mkComponent('my::Module');

  $obj = php::mkInstance('my_Class');

</code>


Of course, additional arguments can be fed
to the constructors in case of object-
instantiation (mkComponent and mkInstance).
Just pass them as additional arguments...

<code>

  $comp = php::mkComponent('my::Module', array( opt1 = >'hello' ), 'arg2' );

</code>

greets, joko.


p.s.:
To actually implement your proposal one-by-one:

Using the Exporter, it should be quite easy
to alias php::mkComponent to php::getInstance.
Adding your proposed php::useNamespace, the 
missing functionality (provided by php::getInstance) 
would be added as a fallback mechanism at
the top of php::mkComponent:
  + prefix modulename with namespace if desired (set by 'useNamespace')

Here is the glitch: We actually have two *different*
types of namespaces following this proposed component
architecture:
  - ClassNamespace
  - ModuleNamespace


[...] again - the post scriptum became way too long,
so got refactored to a seperate document posted elsewhere -
a reference will be added later....  
The title will be: "DummyNamespaces in PHP - final proposal" [...]

But of course i still forgot to add some links, here they are:
@topic source(cvs)
@link http://cvs.netfrag.org/nfo/php/libs/org.netfrag.glib/php_extensions.php
@link http://cvs.netfrag.org/nfo/php/libs/org.netfrag.glib/Exporter.php

@topic doc(api)
@link http://api.netfrag.org/
@link http://netfrag.org/docs/code/api/org.netfrag/org.netfrag.glib/php.html
@link http://netfrag.org/docs/code/api/org.netfrag/org.netfrag.glib/Exporter.html
