-
-
Notifications
You must be signed in to change notification settings - Fork 22
/
Copy pathYiiCaster.php
38 lines (35 loc) · 892 Bytes
/
YiiCaster.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
<?php
/**
* @link https://www.yiiframework.com/
* @copyright Copyright (c) 2008 Yii Software LLC
* @license https://www.yiiframework.com/license/
*/
namespace yii\shell;
use Symfony\Component\VarDumper\Caster\Caster;
use yii\db\ActiveRecord;
/**
* YiiCaster provides wrapper for casters of psysh
*
* @author Daniel Gomez Pan <[email protected]>
* @since 2.0
*/
class YiiCaster
{
/**
* Get an array representing the properties of a model.
*
* @param \yii\db\ActiveRecord $model
* @return array
*/
public static function castModel(ActiveRecord $model)
{
$attributes = array_merge(
$model->getAttributes(), $model->getRelatedRecords()
);
$results = [];
foreach ($attributes as $key => $value) {
$results[Caster::PREFIX_VIRTUAL.$key] = $value;
}
return $results;
}
}