/**
  * Instantiate a cache pattern
  *
  * @param  string|Pattern\PatternInterface $patternName
  * @param  array|Traversable|Pattern\PatternOptions $options
  * @return Pattern\PatternInterface
  * @throws Exception\InvalidArgumentException
  */
 public static function factory($patternName, $options = [])
 {
     if ($options instanceof Pattern\PatternOptions) {
         $options = $options->toArray();
     }
     if ($options instanceof Traversable) {
         $options = ArrayUtils::iteratorToArray($options);
     }
     if (!is_array($options)) {
         throw new Exception\InvalidArgumentException(sprintf('%s expects an array, Traversable object, or %s\\Pattern\\PatternOptions object; received "%s"', __METHOD__, __NAMESPACE__, is_object($options) ? get_class($options) : gettype($options)));
     }
     if ($patternName instanceof Pattern\PatternInterface) {
         $patternName->setOptions(new Pattern\PatternOptions($options));
         return $patternName;
     }
     return static::getPluginManager()->get($patternName, $options);
 }
Exemple #2
0
 public function testOptionsGetAndSetDefault()
 {
     $options = $this->_pattern->getOptions();
     $this->_pattern->setOptions($options);
     $this->assertSame($options, $this->_pattern->getOptions());
 }