Skip to content

Commit e4e01b3

Browse files
igorsantos07koenpunt
authored andcommitted
Allows for aliased methods in serialization, so we can do stuff like $model->to_array(['methods' => ['get_name' => 'name']]);
1 parent e62d04f commit e4e01b3

File tree

1 file changed

+5
-2
lines changed

1 file changed

+5
-2
lines changed

lib/Serialization.php

+5-2
Original file line numberDiff line numberDiff line change
@@ -136,10 +136,13 @@ private function check_methods()
136136
{
137137
$this->options_to_a('methods');
138138

139-
foreach ($this->options['methods'] as $method)
139+
foreach ($this->options['methods'] as $method => $name)
140140
{
141+
if (is_numeric($method))
142+
$method = $name;
143+
141144
if (method_exists($this->model, $method))
142-
$this->attributes[$method] = $this->model->$method();
145+
$this->attributes[$name] = $this->model->$method();
143146
}
144147
}
145148
}

0 commit comments

Comments
 (0)