123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657 |
- <?php
- /*
- * This file is part of the Predis package.
- *
- * (c) Daniele Alessandri <suppakilla@gmail.com>
- *
- * For the full copyright and license information, please view the LICENSE
- * file that was distributed with this source code.
- */
- namespace Predis\Options;
- use Predis\Network\IConnectionCluster;
- use Predis\Network\PredisCluster;
- class ClientCluster extends Option
- {
- protected function checkInstance($cluster)
- {
- if (!$cluster instanceof IConnectionCluster) {
- throw new \InvalidArgumentException(
- 'Instance of Predis\Network\IConnectionCluster expected'
- );
- }
- return $cluster;
- }
- public function validate($value)
- {
- if (is_callable($value)) {
- return $this->checkInstance(call_user_func($value));
- }
- $initializer = $this->getInitializer($value);
- return $this->checkInstance($initializer());
- }
- protected function getInitializer($fqnOrType)
- {
- switch ($fqnOrType) {
- case 'predis':
- return function() { return new PredisCluster(); };
- default:
- return function() use($fqnOrType) {
- return new $fqnOrType();
- };
- }
- }
- public function getDefault()
- {
- return new PredisCluster();
- }
- }
|