diff options
author | Pierre Schmitz <pierre@archlinux.de> | 2015-12-17 09:15:42 +0100 |
---|---|---|
committer | Pierre Schmitz <pierre@archlinux.de> | 2015-12-17 09:44:51 +0100 |
commit | a1789ddde42033f1b05cc4929491214ee6e79383 (patch) | |
tree | 63615735c4ddffaaabf2428946bb26f90899f7bf /vendor/ruflin/elastica/lib/Elastica/Connection/Strategy/StrategyFactory.php | |
parent | 9e06a62f265e3a2aaabecc598d4bc617e06fa32d (diff) |
Update to MediaWiki 1.26.0
Diffstat (limited to 'vendor/ruflin/elastica/lib/Elastica/Connection/Strategy/StrategyFactory.php')
-rw-r--r-- | vendor/ruflin/elastica/lib/Elastica/Connection/Strategy/StrategyFactory.php | 45 |
1 files changed, 45 insertions, 0 deletions
diff --git a/vendor/ruflin/elastica/lib/Elastica/Connection/Strategy/StrategyFactory.php b/vendor/ruflin/elastica/lib/Elastica/Connection/Strategy/StrategyFactory.php new file mode 100644 index 00000000..7590ab11 --- /dev/null +++ b/vendor/ruflin/elastica/lib/Elastica/Connection/Strategy/StrategyFactory.php @@ -0,0 +1,45 @@ +<?php +namespace Elastica\Connection\Strategy; + +use Elastica\Exception\InvalidException; + +/** + * Description of StrategyFactory. + * + * @author chabior + */ +class StrategyFactory +{ + /** + * @param mixed|callable|string|StrategyInterface $strategyName + * + * @throws \Elastica\Exception\InvalidException + * + * @return \Elastica\Connection\Strategy\StrategyInterface + */ + public static function create($strategyName) + { + if ($strategyName instanceof StrategyInterface) { + return $strategyName; + } + + if (CallbackStrategy::isValid($strategyName)) { + return new CallbackStrategy($strategyName); + } + + if (is_string($strategyName)) { + $requiredInterface = '\\Elastica\\Connection\\Strategy\\StrategyInterface'; + $predefinedStrategy = '\\Elastica\\Connection\\Strategy\\'.$strategyName; + + if (class_exists($predefinedStrategy) && class_implements($predefinedStrategy, $requiredInterface)) { + return new $predefinedStrategy(); + } + + if (class_exists($strategyName) && class_implements($strategyName, $requiredInterface)) { + return new $strategyName(); + } + } + + throw new InvalidException('Can\'t create strategy instance by given argument'); + } +} |