Skip to content

Commit

Permalink
Merge pull request #3 from docteurklein/magic_get
Browse files Browse the repository at this point in the history
permit magic access to fields data event if empty
  • Loading branch information
chanmix51 committed Dec 3, 2011
2 parents d1883e2 + e66123d commit 947df78
Showing 1 changed file with 64 additions and 52 deletions.
116 changes: 64 additions & 52 deletions Pomm/Object/BaseObject.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,16 +6,16 @@
use Pomm\External\sfInflector;

/**
* BaseObject - Parent for entity classes
*
* BaseObject - Parent for entity classes
*
* @abstract
* @package Pomm
* @version $id$
* @copyright 2011 Grégoire HUBERT
* @copyright 2011 Grégoire HUBERT
* @author Grégoire HUBERT <hubert.greg@gmail.com>
* @license MIT/X11 {@link http://opensource.org/licenses/mit-license.php}
*/
abstract class BaseObject implements \ArrayAccess
abstract class BaseObject implements \ArrayAccess
{
const NONE = 0;
const EXIST = 1;
Expand All @@ -28,9 +28,9 @@ abstract class BaseObject implements \ArrayAccess
protected $primary_key = array();

/**
* __construct
* __construct
* The constructor. This shouldn't be called directly, see BaseObjectMap::createObject() instead
*
*
* @param Array $pk the primary key definition
* @param Array $fields_definition the fields declared to be stored in the database
* @access public
Expand All @@ -43,23 +43,25 @@ public function __construct(Array $pk = array(), Array $fields_definition = arra
}

/**
* get
* Returns the $name value
*
* get
* Returns the $name value
*
* @param string $var The key you want to retrieve value from
* @access public
* @return mixed
*/
public function get($var)
{
return $this->fields[$var];
if ($this->has($var)) {
return $this->fields[$var];
}
}

/**
* has
* has
* Returns true if the given key exists
*
* @param string $var
*
* @param string $var
* @access public
* @return boolean
*/
Expand All @@ -69,11 +71,11 @@ public function has($var)
}

/**
* __call
* __call
* Allows dynamic methods getXXX, setXXX or addXXX
*
* @param mixed $method
* @param mixed $arguments
*
* @param mixed $method
* @param mixed $arguments
* @access public
* @return mixed
*/
Expand All @@ -86,10 +88,8 @@ public function __call($method, $arguments)
{
case 'set':
return $this->set($attribute, $arguments[0]);
break;
case 'get':
return $this->get($attribute);
break;
case 'add':
return $this->add($attribute, $arguments[0]);
default:
Expand All @@ -98,10 +98,10 @@ public function __call($method, $arguments)
}

/**
* hydrate
* hydrate
* Merge internal values with given $values in the object
*
* @param Array $values
*
* @param Array $values
* @access public
* @return void
*/
Expand All @@ -111,10 +111,10 @@ public final function hydrate(Array $values)
}

/**
* convert
* convert
* Make all keys lowercase and hydrate the object
*
* @param Array $values
*
* @param Array $values
* @access public
* @return void
*/
Expand All @@ -130,10 +130,10 @@ public function convert(Array $values)
}

/**
* _getStatus
* _getStatus
* Returns the current status of the instance
* can be self::NONE, self::EXIST and SELF::MODIFIED
*
*
* @access public
* @return integer
*/
Expand All @@ -143,10 +143,10 @@ public function _getStatus()
}

/**
* _setStatus
* _setStatus
* Forces the status of the object
*
* @param integer $status
*
* @param integer $status
* @access public
* @return void
*/
Expand All @@ -156,9 +156,9 @@ public function _setStatus($status)
}

/**
* extract
* extract
* Returns the fields array
*
*
* @access public
* @return array
*/
Expand All @@ -168,9 +168,9 @@ public function extract()
}

/**
* setPrimaryKey
*
* @param Array $keys
* setPrimaryKey
*
* @param Array $keys
* @access public
* @return void
*/
Expand All @@ -180,9 +180,9 @@ public function setPrimaryKey(Array $keys)
}

/**
* getPrimaryKey
* getPrimaryKey
* returns the values of the instance's primary key
*
*
* @access public
* @return void
*/
Expand All @@ -198,25 +198,37 @@ public function getPrimaryKey()
}

/**
* __set
* __set
* PHP magic to set attributes
*
* @param string $var
* @param mixed $value
*
* @param string $var
* @param mixed $value
* @access public
* @return void
*/
public function __set($var, $value)
{
$this->set($var, $value);
}
/**
* __get
* PHP magic to get attributes
*
* @param string $var
* @access public
* @return void
*/
public function __get($var)
{
$this->get($var);
}

/**
* set
* set
* Set a value in the varholder
*
* @param string $var
* @param mixed $value
* @param string $var
* @param mixed $value
* @access public
* @return void
*/
Expand All @@ -227,12 +239,12 @@ public function set($var, $value)
}

/**
* add
* add
* When the corresponding attribute is an array, call this method
* to set values
*
* @param string $var
* @param mixed $value
*
* @param string $var
* @param mixed $value
* @access public
* @return void
*/
Expand All @@ -256,9 +268,9 @@ public function add($var, $value)
}

/**
* isNew
* isNew
* is the current object self::NEW (does not it exist in the database already ?)
*
*
* @access public
* @return boolean
*/
Expand All @@ -268,9 +280,9 @@ public function isNew()
}

/**
* isModified
* isModified
* Has the object been modified since we know it ?
*
*
* @access public
* @return boolean
*/
Expand Down

0 comments on commit 947df78

Please sign in to comment.