Created
April 24, 2013 21:29
-
-
Save mertenvg/5455732 to your computer and use it in GitHub Desktop.
Get object or class vars of a specified class from an external scope ensuring that retrieved vars are public onlyue
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
namespace EntityMarshal; | |
class ForeignScope | |
{ | |
/** | |
* @var ForeignScope Singleton instance. | |
*/ | |
private static $instance; | |
/** | |
* @return ForeignScope | |
*/ | |
public static function getInstance() | |
{ | |
if (is_null(self::$instance)) { | |
$self = __CLASS__; | |
self::$instance = new $self(); | |
} | |
return self::$instance; | |
} | |
/** | |
* Private constructor to ensure singletonnnnness | |
*/ | |
private function __construct() | |
{ | |
} | |
/** | |
* Retrieve the object vars of $object from a public scope. | |
* | |
* @param object $object | |
* | |
* @return array | |
*/ | |
public function getObjectVars($object) | |
{ | |
return get_object_vars($object); | |
} | |
/** | |
* Retrieve the class vars of $class from a public scope. | |
* | |
* @param string $class | |
* | |
* @return array | |
*/ | |
public function getClassVars($class) | |
{ | |
return get_class_vars($class); | |
} | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment