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.