aboutsummaryrefslogtreecommitdiff
path: root/cli/Commands/Base/TinkerCaster.php
blob: 168de58c371502f9fc9b5711eb5d5c52957ef32c (plain)
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
39
40
41
42
43
44
45
46
47
48
49
50
<?php

namespace Studip\Cli\Commands\Base;

use Illuminate\Support\Collection;
use SimpleCollection;
use SimpleORMap;
use Symfony\Component\VarDumper\Caster\Caster;

class TinkerCaster
{
    /**
     * Get an array representing the properties of a collection.
     *
     * @param  SimpleCollection  $collection
     * @return array
     */
    public static function castCollection(Collection $collection)
    {
        return [
            Caster::PREFIX_VIRTUAL . 'all' => $collection->all(),
        ];
    }

    /**
     * Get an array representing the properties of a collection.
     *
     * @param  SimpleORMap $collection
     * @return array
     */
    public static function castModel(SimpleORMap $model)
    {
        return [
            Caster::PREFIX_VIRTUAL . 'attributes' => $model->toArray(),
        ];
    }

    /**
     * Get an array representing the properties of a collection.
     *
     * @param  SimpleCollection  $collection
     * @return array
     */
    public static function castSimpleCollection(SimpleCollection $collection)
    {
        return [
            Caster::PREFIX_VIRTUAL . 'all' => [...$collection],
        ];
    }
}