Skip to content

Commit

Permalink
Adding some de-constructors for improving garbage collections.
Browse files Browse the repository at this point in the history
  • Loading branch information
ziminji committed Aug 23, 2015
1 parent b5a033b commit 2417bfb
Show file tree
Hide file tree
Showing 11 changed files with 175 additions and 39 deletions.
10 changes: 10 additions & 0 deletions src/classes/Leap/Core/Config.php
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,16 @@ public function __construct($uri) {
$this->uri = $uri;
}

/**
* This method releases any internal references to an object.
*
* @access public
*/
public function __destruct() {
parent::__destruct();
unset($this->uri);
}

/**
* This method returns the processed resource as a collection.
*
Expand Down
12 changes: 11 additions & 1 deletion src/classes/Leap/Core/DB/DataSource.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
* @access public
* @class
* @package Leap\Core\DB
* @version 2014-07-04
* @version 2015-08-23
*/
class DataSource extends \Leap\Core\Object {

Expand Down Expand Up @@ -87,6 +87,16 @@ public function __construct($config) {
}
}

/**
* This method releases any internal references to an object.
*
* @access public
*/
public function __destruct() {
parent::__destruct();
unset($this->settings);
}

/**
* This method returns the value associated with the specified property.
*
Expand Down
15 changes: 14 additions & 1 deletion src/classes/Leap/Core/DB/ResultSet.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
* @access public
* @class
* @package Leap\Core\DB
* @version 2014-05-16
* @version 2015-08-23
*/
class ResultSet extends \Leap\Core\Object implements \ArrayAccess, \Countable, \Iterator, \SeekableIterator, \Leap\Core\GC\IDisposable {

Expand Down Expand Up @@ -89,6 +89,19 @@ public function __construct($buffer, $type = 'array') {
$this->type = $type;
}

/**
* This method releases any internal references to an object.
*
* @access public
*/
public function __destruct() {
parent::__destruct();
unset($this->position);
unset($this->records);
unset($this->size);
unset($this->type);
}

/**
* This method returns an array of records of the desired object type.
*
Expand Down
13 changes: 12 additions & 1 deletion src/classes/Leap/Core/DB/Schema.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
* @access public
* @class
* @package Leap\Core\DB
* @version 2014-07-04
* @version 2015-08-23
*/
abstract class Schema extends \Leap\Core\Object {

Expand Down Expand Up @@ -59,6 +59,17 @@ public function __construct(\Leap\Core\DB\DataSource $data_source) {
$this->data_source = $data_source;
}

/**
* This method releases any internal references to an object.
*
* @access public
*/
public function __destruct() {
parent::__destruct();
unset($this->data_source);
unset($this->precompiler);
}

/**
* This method returns an associated array of default properties for the specified
* SQL data type.
Expand Down
9 changes: 8 additions & 1 deletion src/classes/Leap/Core/IObject.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
* @access public
* @interface
* @package Leap\Core
* @version 2014-06-10
* @version 2015-08-23
*/
interface IObject {

Expand All @@ -36,6 +36,13 @@ interface IObject {
*/
public function __debug();

/**
* This method releases any internal references to an object.
*
* @access public
*/
public function __destruct();

/**
* This method returns whether the specified object is equal to the called object.
*
Expand Down
11 changes: 10 additions & 1 deletion src/classes/Leap/Core/Object.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
* @access public
* @class
* @package Leap\Core
* @version 2014-01-25
* @version 2015-08-23
*/
abstract class Object implements \Leap\Core\IObject {

Expand All @@ -50,6 +50,15 @@ public function __debug() {
var_dump($this);
}

/**
* This method releases any internal references to an object.
*
* @access public
*/
public function __destruct() {
// do nothing
}

/**
* This method returns whether the specified object is equal to the called object.
*
Expand Down
48 changes: 33 additions & 15 deletions src/classes/Leap/Core/Web/HTTP/Auth.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
* @access public
* @class
* @package Leap\Core\DB
* @version 2014-01-26
* @version 2015-08-23
*/
class Auth extends \Auth {

Expand All @@ -37,14 +37,7 @@ class Auth extends \Auth {
* @access protected
* @var array
*/
protected $columns = array(
'role_id' => 'id',
'role_name' => 'name',
'token' => 'token',
'user_id' => 'id',
'user_username' => 'username',
'user_email' => 'email',
);
protected $columns;

/**
* This variable stores a list of errors that of which have been encountered
Expand All @@ -53,7 +46,7 @@ class Auth extends \Auth {
* @access protected
* @var array
*/
protected $errors = array();
protected $errors;

/**
* This variable stores a list of the models and their respective database
Expand All @@ -62,11 +55,7 @@ class Auth extends \Auth {
* @access protected
* @var array
*/
protected $models = array(
'role' => 'Role',
'user' => 'User',
'token' => 'User_Token',
);
protected $models;

/**
* This constructor initializes the class using the specified config information.
Expand All @@ -79,6 +68,12 @@ class Auth extends \Auth {
public function __construct($config = NULL) {
parent::__construct($config);

$this->models = array(
'role' => 'Role',
'user' => 'User',
'token' => 'User_Token',
);

if (isset($config['models'])) {
if (isset($config['models']['role'])) {
$this->models['role'] = $config['models']['role'];
Expand All @@ -91,6 +86,15 @@ public function __construct($config = NULL) {
}
}

$this->columns = array(
'role_id' => 'id',
'role_name' => 'name',
'token' => 'token',
'user_id' => 'id',
'user_username' => 'username',
'user_email' => 'email',
);

if (isset($config['columns'])) {
if (isset($config['columns']['role_id'])) {
$this->columns['role_id'] = $config['columns']['role_id'];
Expand All @@ -112,11 +116,25 @@ public function __construct($config = NULL) {
}
}

$this->errors = array();

if (empty($config['login_with_email']) AND empty($config['login_with_username'])) {
throw new \Leap\Core\Throwable\Runtime\Exception('Message: Unable to load configuration. Reason: A valid "login_with" setting must be set in you auth config file.');
}
}

/**
* This method releases any internal references to an object.
*
* @access public
*/
public function __destruct() {
parent::__destruct();
unset($this->columns);
unset($this->errors);
unset($this->models);
}

/**
* This method attempts to log the user in based on the "authautologin" cookie.
*
Expand Down
40 changes: 31 additions & 9 deletions src/classes/Leap/Core/Web/HTTP/Auth/Session.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
* @access public
* @class
* @package Leap\Core\Web\HTTP
* @version 2014-01-25
* @version 2015-08-23
*/
class Session extends \Session {

Expand All @@ -37,19 +37,15 @@ class Session extends \Session {
* @access protected
* @var array
*/
protected $columns = array(
'session_id' => 'id',
'last_active' => 'last_active',
'contents' => 'contents',
);
protected $columns;

/**
* This variable stores how often a garbage collection request is made.
*
* @access protected
* @var integer
*/
protected $gc = 500;
protected $gc;

/**
* This variable stores the current session id.
Expand All @@ -65,7 +61,7 @@ class Session extends \Session {
* @access protected
* @var string
*/
protected $table = '\\Leap\\Core\\Web\\HTTP\\Auth\\Model\\Session';
protected $table;

/**
* This variable stores the old session id.
Expand All @@ -85,20 +81,32 @@ class Session extends \Session {
* @param string $id the session id
*/
public function __construct(Array $config = NULL, $id = NULL) {
// Set the table name
if (isset($config['table'])) {
$this->table = (string) $config['table'];
}
else {
$this->table = '\\Leap\\Core\\Web\\HTTP\\Auth\\Model\\Session';
}

// Set the gc chance
if (isset($config['gc'])) {
$this->gc = (int) $config['gc'];
}
else {
$this->gc = 500;
}

// Overload column names
if (isset($config['columns'])) {
$this->columns = $config['columns'];
}
else {
$this->columns = array(
'session_id' => 'id',
'last_active' => 'last_active',
'contents' => 'contents',
);
}

parent::__construct($config, $id);

Expand All @@ -109,6 +117,20 @@ public function __construct(Array $config = NULL, $id = NULL) {
}
}

/**
* This method releases any internal references to an object.
*
* @access public
*/
public function __destruct() {
parent::__destruct();
unset($this->columns);
unset($this->gc);
unset($this->session_id);
unset($this->table);
unset($this->update_id);
}

/**
* This method destroys the current session.
*
Expand Down
Loading

0 comments on commit 2417bfb

Please sign in to comment.