/** * Obtain the session key. * * For this adapter, it is a UUID based on the SERVER_ADDR variable. * * @return string UUID. */ public static function key() { $context = function ($value) use(&$config) { return isset($_SERVER['SERVER_ADDR']) ? $_SERVER['SERVER_ADDR'] : '127.0.0.1'; }; return String::uuid($context); }
public static function __init() { parent::__init(); static::applyFilter('create', function ($self, $params, $chain) { if (empty($params['data']['id'])) { $params['data']['id'] = String::uuid(); } return $chain->next($self, $params, $chain); }); }
/** * testMultipleUuidGeneration method * * @return void */ public function testMultipleUuidGeneration() { $check = array(); $count = 50; $pattern = "/^[a-f0-9]{8}-[a-f0-9]{4}-4[a-f0-9]{3}-[8-9a-b][a-f0-9]{3}-[a-f0-9]{12}\$/"; for ($i = 0; $i < $count; $i++) { $result = String::uuid(); $match = preg_match($pattern, $result); $this->assertTrue($match); $this->assertFalse(in_array($result, $check)); $check[] = $result; } }
/** * Tests generating a UUID with seed data provided by an anonymous function. * * @return void */ public function testGeneratingUuidWithCallback() { $pattern = "/^[a-f0-9]{8}-[a-f0-9]{4}-[a-f0-9]{4}-[a-f0-9]{4}-[a-f0-9]{12}\$/"; $result = String::uuid(function ($value) { if ($value == 'SERVER_ADDR') { return '::1'; } }); $this->assertPattern($pattern, $result); $result = String::uuid(function ($value) { if ($value == 'HOST') { return '127.0.0.1'; } }); $this->assertPattern($pattern, $result); $result = String::uuid(function ($value) { if ($value == 'SERVER_ADDR') { return '127.0.0.2'; } }); $this->assertPattern($pattern, $result); }
/** * Obtain the session key. * * For this adapter, it is a UUID. * * @return string UUID. */ public static function key() { return String::uuid(); }
public function testUpdate() { $this->_createGalleriesWithImages(); $options = array('conditions' => array('gallery_id' => 1)); $uuid = String::uuid(); $image = Images::find('first', $options); $image->title = $uuid; $firstID = $image->id; $image->save(); $this->assertEqual($uuid, Images::find('first', $options)->title); $uuid = String::uuid(); Images::update(array('title' => $uuid), array('id' => $firstID)); $this->assertEqual($uuid, Images::find('first', $options)->title); $this->images[0]['title'] = $uuid; }