Subversion Repositories PHPX

Rev

Rev 51 | Rev 54 | Go to most recent revision | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 51 Rev 52
Line 6... Line 6...
6
* Interface to be implemented if the model should be localizable
6
* Interface to be implemented if the model should be localizable
7
*/
7
*/
8
interface ILocalizable
8
interface ILocalizable
9
{
9
{
10
  /**
10
  /**
11
   * Localizes this model.  The actual implementation is left to the model class
11
   * Localizes this model.  The actual implementation is left to
12
   * implementing this interface.
12
   * the model class implementing this interface.
13
   */
13
   */
14
  function localize();
14
  function localize ();
15
}
15
}
16
16
17
/**
17
/**
18
 * Abstract model class
18
 * Abstract model class
19
 *
19
 *
Line 28... Line 28...
28
   * Creates a new model object
28
   * Creates a new model object
29
   *
29
   *
30
   * @param array $data     Initialization data (optional)
30
   * @param array $data     Initialization data (optional)
31
   * @param array $mapping  Mapping for initialization data (optional)
31
   * @param array $mapping  Mapping for initialization data (optional)
32
   */
32
   */
33
  protected function __construct(array $data = null, array $mapping = null)
33
  protected function __construct (array $data = null, array $mapping = null)
34
  {
34
  {
35
    if (!is_null($data))
35
    if (!is_null($data))
36
    {
36
    {
37
      $this->map($data, $mapping);
37
      $this->map($data, $mapping);
38
    }
38
    }
Line 43... Line 43...
43
   *
43
   *
44
   * @param string $name
44
   * @param string $name
45
   * @throws ModelPropertyException
45
   * @throws ModelPropertyException
46
   * @return mixed
46
   * @return mixed
47
   */
47
   */
48
  public function __get($name)
48
  public function __get ($name)
49
  {
49
  {
50
    /* Support for Object-Relational Mappers */
50
    /* Support for Object-Relational Mappers */
51
    if (strpos($name, 'persistent') === 0)
51
//     if (strpos($name, 'persistent') === 0)
52
    {
52
//     {
53
      $class = get_class($this);
53
//       $class = get_class($this);
54
      return $class::${$name};
54
//       return $class::${$name};
55
    }
55
//     }
56
56
57
    $method = 'get' . ucfirst($name);
57
    $method = 'get' . ucfirst($name);
58
58
59
    if (method_exists($this, $method))
59
    if (method_exists($this, $method))
60
    {
60
    {
Line 74... Line 74...
74
   *
74
   *
75
   * @param string $name
75
   * @param string $name
76
   * @param mixed $value  The new property value before assignment
76
   * @param mixed $value  The new property value before assignment
77
   * @throws ModelPropertyException
77
   * @throws ModelPropertyException
78
   */
78
   */
79
  public function __set($name, $value)
79
  public function __set ($name, $value)
80
  {
80
  {
81
    $method = 'set' . ucfirst($name);
81
    $method = 'set' . ucfirst($name);
82
82
83
    if (method_exists($this, $method))
83
    if (method_exists($this, $method))
84
    {
84
    {
Line 100... Line 100...
100
   *
100
   *
101
   * @param string $varName
101
   * @param string $varName
102
   * @return boolean
102
   * @return boolean
103
   * @see getPropertyVars()
103
   * @see getPropertyVars()
104
   */
104
   */
105
  private static function _isPropertyVar($varName)
105
  private static function _isPropertyVar ($varName)
106
  {
106
  {
107
    return preg_match('/^_\\w/', $varName) > 0;
107
    return preg_match('/^_\\w/', $varName) > 0;
108
  }
108
  }
109
109
110
  /**
110
  /**
Line 113... Line 113...
113
   *
113
   *
114
   * @param string $varName
114
   * @param string $varName
115
   * @return string
115
   * @return string
116
   * @see getPropertyVars()
116
   * @see getPropertyVars()
117
   */
117
   */
118
  private static function _toPropertyVar($varName)
118
  private static function _toPropertyVar ($varName)
119
  {
119
  {
120
    return preg_replace('/^_(\\w)/', '\\1', $varName);
120
    return preg_replace('/^_(\\w)/', '\\1', $varName);
121
  }
121
  }
122
122
123
  /**
123
  /**
124
   * Returns the public names of the property variables of a {@link Model}
124
   * Returns the public names of the property variables of a {@link Model}
125
   * as an array of strings
125
   * as an array of strings
126
   *
126
   *
127
   * @return array
127
   * @return array
128
   */
128
   */
129
  public function getPropertyVars()
129
  public function getPropertyVars ()
130
  {
130
  {
131
    return array_map(
131
    return array_map(
132
      array('self', '_toPropertyVar'),
132
      array('self', '_toPropertyVar'),
133
      array_filter(
133
      array_filter(
134
        array_keys(get_object_vars($this)),
134
        array_keys(get_object_vars($this)),
Line 157... Line 157...
157
   *   <p>If <code>true</code>, <em>only</em> the keys of $data that are present
157
   *   <p>If <code>true</code>, <em>only</em> the keys of $data that are present
158
   *   in $mapping are mapped.</p>
158
   *   in $mapping are mapped.</p>
159
   * @return AbstractModel
159
   * @return AbstractModel
160
   *   The modified object
160
   *   The modified object
161
   */
161
   */
162
  public function map(array $data, array $mapping = null, $exclusive = false)
162
  public function map (array $data, array $mapping = null, $exclusive = false)
163
  {
163
  {
164
    if (is_null($mapping))
164
    if (is_null($mapping))
165
    {
165
    {
166
      foreach ($data as $key => $value)
166
      foreach ($data as $key => $value)
167
      {
167
      {