Open Journal Systems  3.3.0
MemoizingInflector.php
1 <?php
2 
3 namespace Guzzle\Inflection;
4 
9 {
11  protected $cache = array(
12  'snake' => array(),
13  'camel' => array()
14  );
15 
17  protected $maxCacheSize;
18 
20  protected $decoratedInflector;
21 
26  public function __construct(InflectorInterface $inflector, $maxCacheSize = 500)
27  {
28  $this->decoratedInflector = $inflector;
29  $this->maxCacheSize = $maxCacheSize;
30  }
31 
32  public function snake($word)
33  {
34  if (!isset($this->cache['snake'][$word])) {
35  $this->pruneCache('snake');
36  $this->cache['snake'][$word] = $this->decoratedInflector->snake($word);
37  }
38 
39  return $this->cache['snake'][$word];
40  }
41 
49  public function camel($word)
50  {
51  if (!isset($this->cache['camel'][$word])) {
52  $this->pruneCache('camel');
53  $this->cache['camel'][$word] = $this->decoratedInflector->camel($word);
54  }
55 
56  return $this->cache['camel'][$word];
57  }
58 
64  protected function pruneCache($cache)
65  {
66  if (count($this->cache[$cache]) == $this->maxCacheSize) {
67  $this->cache[$cache] = array_slice($this->cache[$cache], $this->maxCacheSize * 0.2);
68  }
69  }
70 }
Guzzle\Inflection\MemoizingInflector\$cache
$cache
Definition: MemoizingInflector.php:14
Guzzle\Inflection\MemoizingInflector\$decoratedInflector
$decoratedInflector
Definition: MemoizingInflector.php:29
Guzzle\Inflection\InflectorInterface
Definition: InflectorInterface.php:8
Guzzle\Inflection
Definition: Inflector.php:3
Guzzle\Inflection\MemoizingInflector
Definition: MemoizingInflector.php:8
Guzzle\Inflection\MemoizingInflector\__construct
__construct(InflectorInterface $inflector, $maxCacheSize=500)
Definition: MemoizingInflector.php:35
Guzzle\Inflection\MemoizingInflector\camel
camel($word)
Definition: MemoizingInflector.php:58
Guzzle\Inflection\MemoizingInflector\pruneCache
pruneCache($cache)
Definition: MemoizingInflector.php:73
Guzzle\Inflection\MemoizingInflector\$maxCacheSize
$maxCacheSize
Definition: MemoizingInflector.php:23
Guzzle\Inflection\MemoizingInflector\snake
snake($word)
Definition: MemoizingInflector.php:41