Autodoc
  • Namespace
  • Class
  • Tree

Namespaces

  • BlueTihi
    • Context
  • Brickrouge
    • Element
      • Nodes
    • Renderer
    • Widget
  • ICanBoogie
    • ActiveRecord
    • AutoConfig
    • CLDR
    • Composer
    • Core
    • Event
    • Exception
    • HTTP
      • Dispatcher
      • Request
    • I18n
      • Translator
    • Mailer
    • Modules
      • Taxonomy
        • Support
      • Thumbnailer
        • Versions
    • Object
    • Operation
      • Dispatcher
    • Prototype
    • Routes
    • Routing
      • Dispatcher
    • Session
  • Icybee
    • ActiveRecord
      • Model
    • ConfigOperation
    • Document
    • EditBlock
    • Element
      • ActionbarContextual
      • ActionbarSearch
      • ActionbarToolbar
    • FormBlock
    • Installer
    • ManageBlock
    • Modules
      • Articles
      • Cache
        • Collection
        • ManageBlock
      • Comments
        • ManageBlock
      • Contents
        • ManageBlock
      • Dashboard
      • Editor
        • Collection
      • Files
        • File
        • ManageBlock
      • Forms
        • Form
        • ManageBlock
      • I18n
      • Images
        • ManageBlock
      • Members
      • Modules
        • ManageBlock
      • Nodes
        • ManageBlock
        • Module
      • Pages
        • BreadcrumbElement
        • LanguagesElement
        • ManageBlock
        • NavigationBranchElement
        • NavigationElement
        • Page
        • PageController
      • Registry
      • Search
      • Seo
      • Sites
        • ManageBlock
      • Taxonomy
        • Terms
          • ManageBlock
        • Vocabulary
          • ManageBlock
      • Users
        • ManageBlock
        • NonceLogin
        • Roles
      • Views
        • ActiveRecordProvider
        • Collection
        • View
    • Operation
      • ActiveRecord
      • Constructor
      • Module
      • Widget
    • Rendering
  • None
  • Patron
  • PHP

Classes

  • Calendar
  • CalendarCollection
  • DateFormatter
  • DateTimeFormatter
  • FileCache
  • Locale
  • LocaleCollection
  • LocalizedDateTime
  • LocalizedObject
  • Provider
  • Repository
  • Retriever
  • RunTimeCache
  • Supplemental
  • TimeFormatter

Interfaces

  • Cache

Exceptions

  • ResourceNotFound
  1 <?php
  2 
  3 /*
  4  * This file is part of the ICanBoogie package.
  5  *
  6  * (c) Olivier Laviale <olivier.laviale@gmail.com>
  7  *
  8  * For the full copyright and license information, please view the LICENSE
  9  * file that was distributed with this source code.
 10  */
 11 
 12 namespace ICanBoogie\CLDR;
 13 
 14 /**
 15  * Cache interface
 16  */
 17 interface Cache
 18 {
 19     /**
 20      * Checks if a key exists in the cache.
 21      *
 22      * @param string $key
 23      */
 24     public function exists($key);
 25 
 26     /**
 27      * Retrieves the data specified by the key from the cache.
 28      *
 29      * @param string $key
 30      */
 31     public function retrieve($key);
 32 
 33     /**
 34      * Stores the specified data in the cache, under the specified key.
 35      *
 36      * @param string $key
 37      * @param mixed $data
 38      */
 39     public function store($key, $data);
 40 }
 41 
 42 /**
 43  * A cache that persists using files.
 44  *
 45  * <pre>
 46  * <?php
 47  *
 48  * use ICanBoogie\CLDR\FileCache;
 49  *
 50  * $cache = new FileCache('/path/to/cached_repository');
 51  * </pre>
 52  */
 53 class FileCache implements Cache
 54 {
 55     protected $root;
 56 
 57     static private function path_to_key($path)
 58     {
 59         return str_replace('/', '--', $path);
 60     }
 61 
 62     public function __construct($root)
 63     {
 64         $this->root = rtrim($root, DIRECTORY_SEPARATOR) . DIRECTORY_SEPARATOR;
 65     }
 66 
 67     public function exists($path)
 68     {
 69         $key = self::path_to_key($path);
 70         $filename = $this->root . $key;
 71 
 72         return file_exists($filename);
 73     }
 74 
 75     public function retrieve($path)
 76     {
 77         $key = self::path_to_key($path);
 78         $filename = $this->root . $key;
 79 
 80         if (!file_exists($filename))
 81         {
 82             return;
 83         }
 84 
 85         return file_get_contents($filename);
 86     }
 87 
 88     public function store($path, $data)
 89     {
 90         $key = self::path_to_key($path);
 91         $filename = $this->root . $key;
 92 
 93         file_put_contents($filename, $data);
 94     }
 95 }
 96 
 97 /**
 98  * A cache that only persists during the run time.
 99  *
100  * This cache is meant to be used as a wrapper to more persistant cache:
101  *
102  * <pre>
103  * <?php
104  *
105  * use ICanBoogie\CLDR\FileCache;
106  * use ICanBoogie\CLDR\RunTimeCache;
107  *
108  * $cache = new RunTimeCache(new FileCache('/path/to/cached_repository'));
109  * </pre>
110  */
111 class RunTimeCache implements Cache
112 {
113     private $cache = array();
114     private $static_cache;
115 
116     public function __construct(Cache $static_cache)
117     {
118         $this->static_cache = $static_cache;
119     }
120 
121     public function exists($path)
122     {
123         if (array_key_exists($path, $this->cache))
124         {
125             return true;
126         }
127 
128         return parent::exists($path);
129     }
130 
131     public function retrieve($path)
132     {
133         if (array_key_exists($path, $this->cache))
134         {
135             return $this->cache[$path];
136         }
137 
138         return $this->cache[$path] = $this->static_cache->retrieve($path);
139     }
140 
141     public function store($path, $data)
142     {
143         $this->cache[$path] = $data;
144 
145         $this->static_cache->store($path, $data);
146     }
147 }
Autodoc API documentation generated by ApiGen 2.8.0