NameSpace

1 view
Skip to first unread message

ProdigyView

unread,
Feb 7, 2012, 3:03:03 PM2/7/12
to mongol...@googlegroups.com
Going through the API, quite a few things have to be changed to make the api complaint with namespaced setups.

Right now I would recommended 2 things:

1. Change the filename to the class names.

Field.php should be MongoLanternField.php, that was it can be namespaced such as

namespace mongolantern/fields;

And then later called using 

use mongolantern/fields/MongoLanternFields.

Otherwise the developer has to change a lot of the file names around.

2. Do not use get class() method

if(true === is_object($document) && 'MongoLanternDocument' == get_class($document)) {

This causes the field named to be returned and compared. So its actually comparing  'MongoLanternDocument' == 'name/space/MongoLanternDocument'. To fix this I wrote a method in the MongoLanternUtilitiy class.

/**
* Returns the class name without the namespaced addition. Should be used in environments that
* namespace their classes.
* @param string $class. The string should already be the name of the classed retrieved using get_class($object)
* @return string $class_name Returns the name of the class without a namepsace
* @access public
*/
public static function getClassName($class) {


if(is_object($class))
$class = get_class($class);


  $class = explode('\\', $class);


    return end($class); 

And now I call it like this:

if(true === is_object($document) && 'MongoLanternDocument' == MongoLanternUtility::getClassName(get_class($document))) {

And the namespace issue is fixed.

Sougata Pal.

unread,
Feb 7, 2012, 9:58:32 PM2/7/12
to mongol...@googlegroups.com
Ok.

Thanks for your suggestions. Could you please submit the latest zipped package here with latest changes so that we can verify and update next release.
--
Thanks
Sougata Pal.
Chief Architect, Techunits
http://in.linkedin.com/in/skallpaul
Contact: +91 9051042886
Reply all
Reply to author
Forward
0 new messages