protected function hydrateUser(array $data)
    {
        // Test for new columns added in v2.0.
        // If they're missing, throw an exception and explain that migration is needed.
        foreach (array(
                    $this->getUserColumns('username'),
                    $this->getUserColumns('isEnabled'),
                    $this->getUserColumns('confirmationToken'),
                    $this->getUserColumns('timePasswordResetRequested')
                ) as $col) {
            if (!array_key_exists($col, $data)) {
                throw new \RuntimeException('Internal error: database schema appears out of date. See https://github.com/jasongrimes/silex-simpleuser/blob/master/sql/MIGRATION.md');
            }
        }

        $userClass = $this->getUserClass();

        /** @var User $user */
        $user = new $userClass($data['email']);

        $user->setId($data['id']);
        $user->setPassword($data['password']);
        $user->setSalt($data['salt']);
        $user->setName($data['name']);
        if ($roles = explode(',', $data['roles'])) {
            $user->setRoles($roles);
        }
        $user->setTimeCreated($data['time_created']);
        $user->setUsername($data['username']);
        $user->setEnabled($data['isEnabled']);
        $user->setConfirmationToken($data['confirmationToken']);
        $user->setTimePasswordResetRequested($data['timePasswordResetRequested']);

        if (!empty($data['customFields'])) {
            $user->setCustomFields($data['customFields']);
        }

        return $user;
    }
protected function hydrateUser(array $data)
    {
        // Test for new columns added in v2.0.
        // If they're missing, throw an exception and explain that migration is needed.
        foreach (array(
                    $this->getUserColumns('username'),
                    $this->getUserColumns('isEnabled'),
                    $this->getUserColumns('confirmationToken'),
                    $this->getUserColumns('timePasswordResetRequested')
                ) as $col) {
            if (!array_key_exists($col, $data)) {
                throw new \RuntimeException('Internal error: database schema appears out of date. See https://github.com/jasongrimes/silex-simpleuser/blob/master/sql/MIGRATION.md');
            }
        }

        $userClass = $this->getUserClass();

        /** @var User $user */
        $user = new $userClass($data['email']);

        $user->setId($data['id']);
        $user->setPassword($data['password']);
        $user->setSalt($data['salt']);
        $user->setName($data['name']);
        if ($roles = explode(',', $data['roles'])) {
            $user->setRoles($roles);
        }
        $user->setTimeCreated($data['time_created']);
        $user->setUsername($data['username']);
        $user->setEnabled($data['isEnabled']);
        $user->setConfirmationToken($data['confirmationToken']);
        $user->setTimePasswordResetRequested($data['timePasswordResetRequested']);

        if (!empty($data['customFields'])) {
            $user->setCustomFields($data['customFields']);
        }

        return $user;
    }
protected function hydrateUser ( array $ data ) { // Test for new columns added in v2.0. // If they're missing, throw an exception and explain that migration is needed. foreach ( array ( $ this -> getUserColumns ( 'username' ) , $ this -> getUserColumns ( 'isEnabled' ) , $ this -> getUserColumns ( 'confirmationToken' ) , $ this -> getUserColumns ( 'timePasswordResetRequested' ) ) as $ col ) { if ( ! array_key_exists ( $ col , $ data ) ) { throw new \ RuntimeException ( 'Internal error: database schema appears out of date. See https://github.com/jasongrimes/silex-simpleuser/blob/master/sql/MIGRATION.md' ) ; } } $ userClass = $ this -> getUserClass ( ) ; /** @var User $user */ $ user = new $ userClass ( $ data [ 'email' ] ) ; $ user -> setId ( $ data [ 'id' ] ) ; $ user -> setPassword ( $ data [ 'password' ] ) ; $ user -> setSalt ( $ data [ 'salt' ] ) ; $ user -> setName ( $ data [ 'name' ] ) ; if ( $ roles = explode ( ',' , $ data [ 'roles' ] ) ) { $ user -> setRoles ( $ roles ) ; } $ user -> setTimeCreated ( $ data [ 'time_created' ] ) ; $ user -> setUsername ( $ data [ 'username' ] ) ; $ user -> setEnabled ( $ data [ 'isEnabled' ] ) ; $ user -> setConfirmationToken ( $ data [ 'confirmationToken' ] ) ; $ user -> setTimePasswordResetRequested ( $ data [ 'timePasswordResetRequested' ] ) ; if ( ! empty ( $ data [ 'customFields' ] ) ) { $ user -> setCustomFields ( $ data [ 'customFields' ] ) ; } return $ user ; }
Reconstitute a User object from stored data.

@param array $data
@return User
@throws \RuntimeException if database schema is out of date.
Reconstitute a User object from stored data .