Skip to content

Commit 568de49

Browse files
committed
Initial release of Solr driver
1 parent a9fb2c3 commit 568de49

File tree

10 files changed

+555
-19
lines changed

10 files changed

+555
-19
lines changed

README.md

Lines changed: 13 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -15,18 +15,19 @@ The simplicity of abstraction: One class for many backend cache. You don't need
1515
### Supported drivers at this day *
1616
:bulb: Feel free to propose a driver by making a new **[Pull Request](https://github.com/PHPSocialNetwork/phpfastcache/compare)**, they are welcome !
1717

18-
| Regular drivers | High performances drivers | Development drivers | Cluster-Aggregated drivers |
19-
|---------------------------------|---------------------------------------------------------------|-------------------------------|-----------------------------------|
20-
| `Apcu` *(APC support removed)* | `Arangodb` | `Devnull` | `FullReplicationCluster` |
21-
| `Dynamodb` (AWS) | `Cassandra` | `Devrandom` | `SemiReplicationCluster` |
22-
| `Files` | `CouchBasev3`<br>_(`Couchbase` for SDK 2 support removed)_ | `Memstatic` | `MasterSlaveReplicationCluster` |
23-
| `Firestore` (GCP) | `Couchdb` | | `RandomReplicationCluster` |
24-
| `Leveldb` | `Mongodb` | | |
25-
| `Memcache(d)` | `Predis` | | |
26-
| `Sqlite` | `Redis` | | |
27-
| `Wincache` | `Ssdb` | | |
28-
| `Zend Disk Cache` | `Zend Memory Cache` | | |
29-
| | | | |
18+
| Regular drivers | High performances drivers | Development drivers | Cluster-Aggregated drivers |
19+
|------------------------------------------------------------------------|------------------------------------------------------------|-------------------------------|-----------------------------------|
20+
| `Apcu` _(APC support removed)_ | `Arangodb` | `Devnull` | `FullReplicationCluster` |
21+
| `Dynamodb` (AWS) | `Cassandra` | `Devrandom` | `SemiReplicationCluster` |
22+
| `Files` | `CouchBasev3`<br>_(`Couchbase` for SDK 2 support removed)_ | `Memstatic` | `MasterSlaveReplicationCluster` |
23+
| `Firestore` (GCP) | `Couchdb` | | `RandomReplicationCluster` |
24+
| `Leveldb` | `Mongodb` | | |
25+
| `Memcache(d)` | `Predis` | | |
26+
| `Solr` _(Via [Solarium 6.x](https://github.com/solariumphp/solarium))_ | `Redis` | | |
27+
| `Sqlite` | `Ssdb` | | |
28+
| `Wincache` | `Zend Memory Cache` | | |
29+
| `Zend Disk Cache` | | | |
30+
| | | | |
3031

3132
\* Driver descriptions available in [DOCS/DRIVERS.md](./docs/DRIVERS.md)
3233

bin/ci/scripts/install_dependencies.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,4 +3,4 @@
33
composer self-update
44
composer validate
55
composer install
6-
composer require -W doctrine/couchdb:dev-master phpfastcache/phpssdb:~1.1.0 predis/predis:~1.1.0 mongodb/mongodb:^1.9 triagens/arangodb:^3.8 aws/aws-sdk-php:~3.0 google/cloud-firestore:^1.20
6+
composer require -W doctrine/couchdb:dev-master phpfastcache/phpssdb:~1.1.0 predis/predis:~1.1.0 mongodb/mongodb:^1.9 triagens/arangodb:^3.8 aws/aws-sdk-php:~3.0 google/cloud-firestore:^1.20 solarium/solarium:~6.1

composer.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
"name": "phpfastcache/phpfastcache",
33
"type" : "library",
44
"description": "PHP Abstract Cache Class - Reduce your database call using cache system. Phpfastcache handles a lot of drivers such as Apc(u), Cassandra, CouchBase, Couchdb, Mongodb, Files, (P)redis, Leveldb, Memcache(d), Ssdb, Sqlite, Wincache, Xcache, Zend Data Cache.",
5-
"keywords": ["abstract", "cache","caching","php cache","mysql cache","apc","apcu","arangodb","dynamodb","memcache","memcached","wincache","files cache","pdo cache","cache class","redis","predis","cookie", "mongodb", "cassandra", "couchdb", "couchbase", "LevelDb", "Ssdb", "Wincache", "xcache","zend","zend disk cache","zend memory cache","zend data cache","zend server"],
5+
"keywords": ["abstract", "cache","caching","php cache","mysql cache","apc","apcu","arangodb","dynamodb","memcache","memcached","wincache","files cache","pdo cache","cache class","redis","predis","cookie", "mongodb", "cassandra", "couchdb", "couchbase", "LevelDb", "Solr", "Ssdb", "Wincache", "xcache","zend","zend disk cache","zend memory cache","zend data cache","zend server"],
66
"homepage": "https://www.phpfastcache.com",
77
"license": "MIT",
88
"minimum-stability": "stable",
@@ -49,6 +49,7 @@
4949
"predis/predis": "^1.1",
5050
"mongodb/mongodb": "^1.9",
5151
"phpfastcache/phpssdb": "~1.1.0",
52+
"solarium/solarium": "~6.1",
5253
"doctrine/couchdb": "^dev-master#9eeb9e5",
5354
"triagens/arangodb": "^3.8",
5455
"google/cloud-firestore": "^1.20",

docs/DRIVERS.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,8 @@
4545
* A very high-performance memory driver using a in-memory data structure storage. More efficient than Predis driver as it is an compiled library.
4646
* Riak **(REMOVED in v8.0.6)**
4747
* A very high-performance NoSQL driver using a key-value pair system.
48+
* Solr **(Added in V9.1)**
49+
* A Solr driver that use Solarium as PHP client for good performances.
4850
* Sqlite
4951
* A Sqlite driver that use serialization for storing data for regular performances. A _$path_ config must be specified, else the system temporary directory will be used.
5052
* Ssdb

lib/Phpfastcache/Drivers/Arangodb/Driver.php

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -136,7 +136,7 @@ protected function driverRead(ExtendedCacheItemInterface $item): ?array
136136
);
137137
}
138138

139-
return $this->decode($document);
139+
return $this->decodeDocument($document);
140140
}
141141

142142
/**
@@ -242,17 +242,16 @@ protected function createCollection($collectionName): bool
242242

243243
/**
244244
* @param ArangoDocument $document
245-
* @return mixed
245+
* @return array
246246
* @throws \Exception
247247
*/
248-
protected function decode(ArangoDocument $document): mixed
248+
protected function decodeDocument(ArangoDocument $document): array
249249
{
250250
$value = [
251251
self::DRIVER_KEY_WRAPPER_INDEX => $document->get(self::DRIVER_KEY_WRAPPER_INDEX),
252252
self::DRIVER_TAGS_WRAPPER_INDEX => $document->get(self::DRIVER_TAGS_WRAPPER_INDEX),
253-
self::DRIVER_DATA_WRAPPER_INDEX => \unserialize(
253+
self::DRIVER_DATA_WRAPPER_INDEX => $this->decode(
254254
$document->get(self::DRIVER_DATA_WRAPPER_INDEX),
255-
['allowed_classes' => true]
256255
),
257256
];
258257

Lines changed: 197 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,197 @@
1+
<?php
2+
/**
3+
*
4+
* This file is part of Phpfastcache.
5+
*
6+
* @license MIT License (MIT)
7+
*
8+
* For full copyright and license information, please see the docs/CREDITS.txt and LICENCE files.
9+
*
10+
* @author Georges.L (Geolim4) <contact@geolim4.com>
11+
* @author Contributors https://github.com/PHPSocialNetwork/phpfastcache/graphs/contributors
12+
*/
13+
14+
declare(strict_types=1);
15+
16+
namespace Phpfastcache\Drivers\Solr;
17+
18+
use Phpfastcache\Config\ConfigurationOption;
19+
use Phpfastcache\Core\Pool\ExtendedCacheItemPoolInterface;
20+
use Phpfastcache\Core\Pool\TaggableCacheItemPoolInterface;
21+
use Phpfastcache\EventManager;
22+
use Phpfastcache\Exceptions\PhpfastcacheInvalidArgumentException;
23+
use Phpfastcache\Exceptions\PhpfastcacheLogicException;
24+
use Psr\EventDispatcher\EventDispatcherInterface;
25+
26+
class Config extends ConfigurationOption
27+
{
28+
protected const DEFAULT_MAPPING_SCHEMA = [
29+
ExtendedCacheItemPoolInterface::DRIVER_KEY_WRAPPER_INDEX => ExtendedCacheItemPoolInterface::DRIVER_KEY_WRAPPER_INDEX . '_s',
30+
ExtendedCacheItemPoolInterface::DRIVER_DATA_WRAPPER_INDEX => ExtendedCacheItemPoolInterface::DRIVER_DATA_WRAPPER_INDEX . '_s',
31+
ExtendedCacheItemPoolInterface::DRIVER_EDATE_WRAPPER_INDEX => ExtendedCacheItemPoolInterface::DRIVER_EDATE_WRAPPER_INDEX . '_ss',
32+
ExtendedCacheItemPoolInterface::DRIVER_MDATE_WRAPPER_INDEX => ExtendedCacheItemPoolInterface::DRIVER_MDATE_WRAPPER_INDEX . '_ss',
33+
ExtendedCacheItemPoolInterface::DRIVER_CDATE_WRAPPER_INDEX => ExtendedCacheItemPoolInterface::DRIVER_CDATE_WRAPPER_INDEX . '_ss',
34+
TaggableCacheItemPoolInterface::DRIVER_TAGS_WRAPPER_INDEX => TaggableCacheItemPoolInterface::DRIVER_TAGS_WRAPPER_INDEX . '_ss',
35+
];
36+
37+
protected string $host = '127.0.0.1';
38+
39+
protected int $port = 8983;
40+
41+
protected string $coreName = '';
42+
43+
protected string $scheme = 'http';
44+
45+
protected string $path = '/'; // Override of ConfigurationOption
46+
47+
protected array $mappingSchema = self::DEFAULT_MAPPING_SCHEMA;
48+
49+
private EventDispatcherInterface $eventDispatcher;
50+
51+
public function __construct(array $parameters = [])
52+
{
53+
$this->eventDispatcher = $this->getDefaultEventDispatcher();
54+
parent::__construct($parameters);
55+
}
56+
57+
/**
58+
* @return string
59+
*/
60+
public function getHost(): string
61+
{
62+
return $this->host;
63+
}
64+
65+
/**
66+
* @param string $host
67+
* @return Config
68+
* @throws PhpfastcacheLogicException
69+
*/
70+
public function setHost(string $host): Config
71+
{
72+
$this->enforceLockedProperty(__FUNCTION__);
73+
$this->host = $host;
74+
return $this;
75+
}
76+
77+
/**
78+
* @return int
79+
*/
80+
public function getPort(): int
81+
{
82+
return $this->port;
83+
}
84+
85+
/**
86+
* @param int $port
87+
* @return Config
88+
* @throws PhpfastcacheLogicException
89+
*/
90+
public function setPort(int $port): Config
91+
{
92+
$this->enforceLockedProperty(__FUNCTION__);
93+
$this->port = $port;
94+
return $this;
95+
}
96+
97+
/**
98+
* @return string
99+
*/
100+
public function getCoreName(): string
101+
{
102+
return $this->coreName;
103+
}
104+
105+
/**
106+
* @param string $coreName
107+
* @return Config
108+
* @throws PhpfastcacheLogicException
109+
*/
110+
public function setCoreName(string $coreName): Config
111+
{
112+
$this->enforceLockedProperty(__FUNCTION__);
113+
$this->coreName = $coreName;
114+
return $this;
115+
}
116+
117+
/**
118+
* @return string
119+
*/
120+
public function getScheme(): string
121+
{
122+
return $this->scheme;
123+
}
124+
125+
/**
126+
* @param string $scheme
127+
* @return Config
128+
* @throws PhpfastcacheLogicException
129+
*/
130+
public function setScheme(string $scheme): Config
131+
{
132+
$this->enforceLockedProperty(__FUNCTION__);
133+
$this->scheme = $scheme;
134+
return $this;
135+
}
136+
137+
/**
138+
* @return EventDispatcherInterface
139+
*/
140+
public function getEventDispatcher(): EventDispatcherInterface
141+
{
142+
return $this->eventDispatcher;
143+
}
144+
145+
/**
146+
* @return EventDispatcherInterface
147+
*/
148+
protected function getDefaultEventDispatcher(): EventDispatcherInterface
149+
{
150+
return new class implements EventDispatcherInterface {
151+
public function dispatch(object $event): object
152+
{
153+
return $event;
154+
}
155+
};
156+
}
157+
158+
/**
159+
* @param EventDispatcherInterface $eventDispatcher
160+
* @return Config
161+
* @throws PhpfastcacheLogicException
162+
*/
163+
public function setEventDispatcher(EventDispatcherInterface $eventDispatcher): Config
164+
{
165+
$this->enforceLockedProperty(__FUNCTION__);
166+
$this->eventDispatcher = $eventDispatcher;
167+
return $this;
168+
}
169+
170+
/**
171+
* @return string[]
172+
*/
173+
public function getMappingSchema(): array
174+
{
175+
return $this->mappingSchema;
176+
}
177+
178+
/**
179+
* @param string[] $mappingSchema
180+
* @return Config
181+
* @throws PhpfastcacheLogicException
182+
* @throws PhpfastcacheInvalidArgumentException
183+
*/
184+
public function setMappingSchema(array $mappingSchema): Config
185+
{
186+
$this->enforceLockedProperty(__FUNCTION__);
187+
188+
$diff = array_diff(array_keys(self::DEFAULT_MAPPING_SCHEMA), array_keys($mappingSchema));
189+
190+
if ($diff) {
191+
throw new PhpfastcacheInvalidArgumentException('Missing keys for the solr mapping schema: ' . \implode(', ', $diff));
192+
}
193+
194+
$this->mappingSchema = $mappingSchema;
195+
return $this;
196+
}
197+
}

0 commit comments

Comments
 (0)