Esempio n. 1
0
 public function testArrayWrapper()
 {
     $array = ['node_1' => 'node1value', 'node_2' => 'node2value', 'node_3' => 'node3value', 'node_4' => 'node4value', 'node_5' => 'node5value'];
     $arrayWrapper = \Magelight\ArrayWrapper::forge($array);
     $this->assertEquals('node1value', $arrayWrapper->getData('node_1'));
     $this->assertEquals(null, $arrayWrapper->getData('node_unexistent'));
     $arrayWrapper->setData('node_6', 'node6value');
     $this->assertEquals('node6value', $arrayWrapper->getData('node_6'));
     $this->assertEquals('node6value', $arrayWrapper->node_6);
     $this->assertTrue($arrayWrapper->allElementsExist(['node_1', 'node_2', 'node_3']));
     unset($arrayWrapper->node_3);
     $this->assertFalse($arrayWrapper->allElementsExist(['node_1', 'node_2', 'node_3']));
     $this->assertTrue(isset($arrayWrapper->node_1));
     $arrayWrapper->other_data = 'other';
     $this->assertEquals('other', $arrayWrapper->other_data);
     $this->assertEquals('other', $arrayWrapper->getData('other_data'));
     $this->assertFalse($arrayWrapper->allElementsExist('node_1', 'node_2', 'node_3'));
     $this->assertFalse($arrayWrapper->allElementsExist());
 }
Esempio n. 2
0
 /**
  * Create user via uLogin service
  *
  * @param string $userData
  * @param string|null $defaultAvatar
  * @return User|null
  */
 public function createViaUlogin($userData, $defaultAvatar = null)
 {
     $user = \Magelight\ArrayWrapper::forge($userData);
     $name = isset($user->first_name) ? $user->first_name . (isset($user->last_name) ? $user->first_name : '') : (isset($user->nickname) ? $user->nickname : $user->email);
     $cityId = null;
     $countryId = \Magelight\Geo\Models\Country::forge()->getCountryIdByName($user->getData('country', ''));
     if (!empty($countryId)) {
         $cityId = \Magelight\Geo\Models\City::forge()->getCityIdByName($user->getData('city', ''));
     }
     $user = static::forge(['is_registered' => 1, 'date_register' => time(), 'openid_provider' => $userData['network'], 'openid_identity' => $userData['identity'], 'openid_uid' => $userData['uid'], 'name' => $name, 'email' => $userData['email'], 'email_verified' => $userData['verified_email'] > 0 ? 1 : 0, 'photo' => isset($userData['photo']) ? $userData['photo'] : $defaultAvatar, 'city' => isset($userData['city']) ? $userData['city'] : '', 'country' => isset($userData['country']) ? $userData['country'] : '', 'city_id' => $cityId, 'country_id' => $countryId], true);
     if ($user->save(true)) {
         if (isset($userData['phone'])) {
             $user->addContact('phone', $userData['phone']);
         }
         return $user;
     }
     return null;
 }