4 * This file is part of the civicrm-cxn-rpc package.
6 * Copyright (c) CiviCRM LLC <info@civicrm.org>
8 * For the full copyright and license information, please view the LICENSE
9 * file that was distributed with this package.
12 namespace Civi\Cxn\Rpc\CxnStore
;
15 * Class JsonFileCxnStore
17 * This is a very simple implementation. DO NOT USE IN PRODUCTION. It is not multithread safe.
19 * @package Civi\Cxn\Rpc\CxnStore
21 class JsonFileCxnStore
implements CxnStoreInterface
{
27 public function __construct($file) {
31 public function getCache() {
33 $this->cache
= $this->load();
38 public function getAll() {
39 return $this->getCache();
42 public function getByCxnId($cxnId) {
43 $cache = $this->getCache();
44 return isset($cache[$cxnId]) ?
$cache[$cxnId] : NULL;
47 public function getByAppId($appId) {
48 $cache = $this->getCache();
49 foreach ($cache as $cxn) {
50 if ($cxn['appId'] == $appId) {
57 public function add($cxn) {
58 $data = $this->load();
59 $data[$cxn['cxnId']] = $cxn;
63 public function remove($cxnId) {
64 $data = $this->load();
65 if (isset($data[$cxnId])) {
74 public function load() {
75 return json_decode(file_get_contents($this->file
), TRUE);
78 public function save($data) {
79 file_put_contents($this->file
, json_encode($data));