123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778 |
- <?php
- namespace Predis\Option;
- use Predis\Connection\MasterSlaveReplication;
- use Predis\Connection\ReplicationConnectionInterface;
- class ClientReplication extends AbstractOption
- {
-
- protected function checkInstance($connection)
- {
- if (!$connection instanceof ReplicationConnectionInterface) {
- throw new \InvalidArgumentException('Instance of Predis\Connection\ReplicationConnectionInterface expected');
- }
- return $connection;
- }
-
- public function filter(ClientOptionsInterface $options, $value)
- {
- if (is_callable($value)) {
- $connection = call_user_func($value, $options, $this);
- if (!$connection instanceof ReplicationConnectionInterface) {
- throw new \InvalidArgumentException('Instance of Predis\Connection\ReplicationConnectionInterface expected');
- }
- return $connection;
- }
- if (is_string($value)) {
- if (!class_exists($value)) {
- throw new \InvalidArgumentException("Class $value does not exist");
- }
- if (!($connection = new $value()) instanceof ReplicationConnectionInterface) {
- throw new \InvalidArgumentException('Instance of Predis\Connection\ReplicationConnectionInterface expected');
- }
- return $connection;
- }
- if ($value == true) {
- return $this->getDefault($options);
- }
- }
-
- public function getDefault(ClientOptionsInterface $options)
- {
- return new MasterSlaveReplication();
- }
- }
|