set() public method

Set a key in the database.
public set ( string $key, mixed $data )
$key string
$data mixed
Beispiel #1
0
 protected function runOperationsTests($config)
 {
     $db = new Flintstone('test', $config);
     $arr = array('foo' => "new\nline");
     $this->assertFalse($db->get('foo'));
     $db->set('foo', 1);
     $db->set('name', 'john');
     $db->set('arr', $arr);
     $this->assertEquals(1, $db->get('foo'));
     $this->assertEquals('john', $db->get('name'));
     $this->assertEquals($arr, $db->get('arr'));
     $db->set('foo', 2);
     $this->assertEquals(2, $db->get('foo'));
     $this->assertEquals('john', $db->get('name'));
     $this->assertEquals($arr, $db->get('arr'));
     $db->delete('name');
     $this->assertFalse($db->get('name'));
     $this->assertEquals($arr, $db->get('arr'));
     $keys = $db->getKeys();
     $this->assertEquals(2, count($keys));
     $this->assertEquals('foo', $keys[0]);
     $this->assertEquals('arr', $keys[1]);
     $data = $db->getAll();
     $this->assertEquals(2, count($data));
     $this->assertEquals(2, $data['foo']);
     $this->assertEquals($arr, $data['arr']);
     $db->flush();
     $this->assertFalse($db->get('foo'));
     $this->assertFalse($db->get('arr'));
     $this->assertEquals(0, count($db->getKeys()));
     $this->assertEquals(0, count($db->getAll()));
     unlink($db->getDatabase()->getPath());
 }
Beispiel #2
0
 /**
  * Send reviews to Slack
  *
  * @param  array   $reviews   list of reviews to send
  * @return boolean successful sending
  */
 public function sendReviews($reviews)
 {
     if (!is_array($reviews) || !count($reviews)) {
         return false;
     }
     if (!isset($this->slackSettings['endpoint'])) {
         if ($this->logger) {
             $this->logger->error('Reviewer: you should set endpoint in Slack settings');
         }
         return false;
     }
     $config = ['username' => 'TJ Reviewer', 'icon' => 'https://i.imgur.com/GX1ASZy.png'];
     if (isset($this->slackSettings['channel'])) {
         $config['channel'] = $this->slackSettings['channel'];
     }
     $slack = new Slack($this->slackSettings['endpoint'], $config);
     foreach ($reviews as $review) {
         $ratingText = '';
         for ($i = 1; $i <= 5; $i++) {
             $ratingText .= $i <= $review['rating'] ? "★" : "☆";
         }
         try {
             if ($this->firstTime === false) {
                 $slack->attach(['fallback' => "{$ratingText} {$review['title']} — {$review['content']}", 'author_name' => $review['application']['name'], 'author_icon' => $review['application']['image'], 'author_link' => $review['application']['link'], 'color' => $review['rating'] >= 4 ? 'good' : ($review['rating'] == 3 ? 'warning' : 'danger'), 'fields' => [['title' => $review['title'], 'value' => $review['content']], ['title' => 'Rating', 'value' => $ratingText, 'short' => true], ['title' => 'Author', 'value' => "<{$review['author']['uri']}|{$review['author']['name']}>", 'short' => true], ['title' => 'Version', 'value' => $review['application']['version'], 'short' => true], ['title' => 'Country', 'value' => $review['country'], 'short' => true]]])->send();
             }
             $this->storage->set("r{$review['id']}", 1);
         } catch (Exception $e) {
             if ($this->logger) {
                 $this->logger->error('Reviewer: exception while sending reviews', ['exception' => $e]);
             }
         }
     }
     return true;
 }
Beispiel #3
0
 public function put($key, $value)
 {
     $this->cache->set($key, $value);
 }