Pantheon\Terminus\Models\User::serialize PHP Метод

serialize() публичный Метод

Formats User object into an associative array for output
public serialize ( ) : array
Результат array $data associative array of data for output
    public function serialize()
    {
        $first_name = $last_name = null;
        if (isset($this->get('profile')->firstname)) {
            $first_name = $this->get('profile')->firstname;
        }
        if (isset($this->get('profile')->lastname)) {
            $last_name = $this->get('profile')->lastname;
        }
        $data = ['firstname' => $first_name, 'lastname' => $last_name, 'email' => $this->get('email'), 'id' => $this->id];
        return $data;
    }

Usage Example

Пример #1
0
 public function testSerialize()
 {
     $expected = array_merge($this->user_data, (array) $this->user_data['profile']);
     unset($expected['profile']);
     unset($expected['full_name']);
     $data = $this->user->serialize();
     $this->assertEquals($expected, $data);
 }