Don't like ads? PRO users don't see any ads ;-)
Guest

Untitled

By: a guest on May 8th, 2012  |  syntax: None  |  size: 1.26 KB  |  hits: 21  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print
Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  1. Usage of the classes for permanent storage:
  2. Použití classes pro permanentní úložiště:
  3.  
  4. <?php
  5. $journal = new AppFileJournal(DATA_DIR . '/user/');
  6. $driver = new AppFileStorage(DATA_DIR . '/user/', $journal);
  7.  
  8. // Get the cache tags
  9. $tags = array();
  10. $tags[] = self::USERID . self::SEPARATOR . $data->user->id;
  11. $tags[] = self::TIMESTAMP . self::SEPARATOR . $data->timestamp;
  12.  
  13. // Get the key
  14. do {
  15.     $key = sha1(uniqid(time()));
  16.     $has = $driver->read($key);
  17. } while(!empty($has));
  18.  
  19. // Store the metrics into cache
  20. return $driver->write($key, $data, array(\Nette\Caching\Cache::TAGS => $tags));
  21. ?>
  22.  
  23. Searching within the storage:
  24. Vyhledávání v rámci storage:
  25.  
  26. <?php
  27. class Mine {
  28.     const USERID = 'userId';
  29.     const TIMESTAMP = 'timestamp';
  30.     const SEPARATOR = '/';
  31.  
  32.     /**
  33.      * Find data by the user id
  34.      *
  35.      * @param int $userId
  36.      */
  37.     public function getDataByUserId($userId) {
  38.         $journal = new App\FileJournal(DATA_DIR . '/user/');
  39.         $driver = new App\FileStorage(DATA_DIR . '/user/', $journal);
  40.  
  41.         $tag = self::USERID . self::SEPARATOR . $userId;
  42.         $nodes = $journal->findNodesByTag($tag);
  43.  
  44.         foreach($nodes as $node) {
  45.             dump($driver->readByFilename($node[App\FileJournal::DATA][App\FileJournal::KEY]));
  46.         }
  47.     }
  48. }