Permalink
Browse files

Will now only load libraries as needed.

Signed-off-by: Caius Durling <git@caius.name>
  • Loading branch information...
1 parent 8d3595c commit 7997687e7ce1029626eb01263353a0e34995b1a2 @Fiona Fiona committed with caius Feb 5, 2009
Showing with 14 additions and 12 deletions.
  1. +14 −12 faker.php
View
@@ -8,6 +8,7 @@
* @copyright 2007 Caius Durling
* @author Caius Durling
* @author ifunk
+ * @author FionaSarah
*
*/
@@ -19,7 +20,7 @@
class Faker
{
- private $_instances = array();
+ public static $_instances = array();
public function __construct()
{
@@ -32,10 +33,19 @@ public function __tostring()
public function &__get( $var )
{
- if (empty($this->_instances[$var])) {
- $this->_instances[$var] = new $var;
+ if (empty(Faker::$_instances[$var])) {
+
+ $filename = "lib/".strtolower($var).".php";
+
+ if(!file_exists($filename))
+ return NULL;
+
+ include $filename;
+
+ Faker::$_instances[$var] = new $var;
+
}
- return $this->_instances[$var];
+ return Faker::$_instances[$var];
}
// todo: use __autoload()
@@ -122,12 +132,4 @@ public function bothify( $string )
}
-// Include the library files
-include 'lib/address.php';
-include 'lib/company.php';
-include 'lib/internet.php';
-include 'lib/name.php';
-include 'lib/phone_number.php';
-include 'lib/lorem.php';
-
?>

0 comments on commit 7997687

Please sign in to comment.