-
-
Notifications
You must be signed in to change notification settings - Fork 2k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Phalcon3/PHP7 Mongo Backend Cache support #12074
Comments
There is no mongoclient class for php 7, you need to use adapter from incubator, but as far as i know it's not working too. |
There is no adapter for mongo cache in incubator |
Then someone needs to create it, just right now old phalcon class is using mongoclient class which is only in php 5.x. In php 7 mongo class was changed and phalcon classes needs to be rewrite. |
any update on this issue? |
As you can see this is marked to resolve for v4.0.0 |
when can v 4.0 release please ? |
Closing in favor of #13855. Will revisit if the community votes for it, or in later versions. |
Quick dirty workaround (should not be used in production). First of all install PHP Library for MongoDB (following instructions). Add fake MongoClient class to your project: class MongoClient
{
private $_connString;
public function __construct(string $server = "mongodb://localhost:27017")
{
$this->_connString = $server;
}
public function selectDB(string $name)
{
return new DirtyMongoDB($this->_connString, $name);
}
}
class DirtyMongoDB
{
private $_connString;
private $_dbName;
public function __construct(string $connString, string $dbName)
{
$this->_connString = $connString;
$this->_dbName = $dbName;
}
public function selectCollection(string $name)
{
return new DirtyMongoCollection($this->_connString, $this->_dbName, $name);
}
}
class DirtyMongoCollection
{
private $_client;
private $_collection;
public function __construct(string $connString, string $dbName, string $collectionName)
{
$this->_client = new \MongoDB\Client($connString);
$this->_collection = $this->_client->$dbName->$collectionName;
}
public function findOne(array $conditions = array())
{
$result = $this->_collection->findOne($conditions);
if($result)
{
$result = $result->getArrayCopy();
}
return $result;
}
public function insert(array $document)
{
return $this->_collection->insertOne($document);
}
public function update(array $criteria, array $document)
{
return $this->_collection->updateOne($criteria, ['$set' => $document]);
}
public function find(array $query = array(), array $fields = array())
{
return $this->_collection->find($query, $fields);
}
public function remove(array $query = array())
{
return $this->_collection->deleteMany($query);
}
public function count(array $query = array())
{
return $this->_collection->count($query);
}
} Further proceed as usual $frontCache = new \Phalcon\Cache\Frontend\None([
'lifetime' => 3600,
]);
$cache = new \Phalcon\Cache\Backend\Mongo(
$frontCache,
[
'server' => 'mongodb://localhost:27017',
'db' => 'robots',
'collection' => 'cache',
]
);
$key = 'some-cache-key';
$data = [
'a' => 'a',
'b' => [
(object) ['asd' => 123]
]
];
$cache->delete($key);
$cache->save($key, $data);
$cache->get($key);
$cache->exists($key);
$cache->flush($key); |
So we are having following code at services.php:
Then we are trying to use it in our trait:
And getting error at last string:
If I am changing Phalcon\Cache\Backend*Mongo* to Phalcon\Cache\Backend*Redis* or any other adapter everything works.
@sergeyklay
The text was updated successfully, but these errors were encountered: