composer package updates
[openemr.git] / vendor / zendframework / zend-cache / src / PatternPluginManager / PatternPluginManagerTrait.php
blobd05160585abec80e1ee33e81d8362372971fad02
1 <?php
2 /**
3 * @see https://github.com/zendframework/zend-cache for the canonical source repository
4 * @copyright Copyright (c) 2018 Zend Technologies USA Inc. (http://www.zend.com)
5 * @license https://github.com/zendframework/zend-cache/blob/master/LICENSE.md New BSD License
6 */
8 namespace Zend\Cache\PatternPluginManager;
10 use Zend\Cache\Exception;
11 use Zend\Cache\Pattern;
12 use Zend\ServiceManager\Exception\InvalidServiceException;
14 /**
15 * Trait providing common logic between FormElementManager implementations.
17 * Trait does not define properties, as the properties common between the
18 * two versions are originally defined in their parent class, causing a
19 * resolution conflict.
21 trait PatternPluginManagerTrait
23 /**
24 * Override build to inject options as PatternOptions instance.
26 * {@inheritDoc}
28 public function build($plugin, array $options = null)
30 if (empty($options)) {
31 return parent::build($plugin);
34 $plugin = parent::build($plugin);
35 $plugin->setOptions(new Pattern\PatternOptions($options));
36 return $plugin;
39 /**
40 * Validate the plugin is of the expected type (v3).
42 * Validates against `$instanceOf`.
44 * @param mixed $instance
45 * @throws InvalidServiceException
47 public function validate($instance)
49 if (! $instance instanceof $this->instanceOf) {
50 throw new InvalidServiceException(sprintf(
51 '%s can only create instances of %s; %s is invalid',
52 get_class($this),
53 $this->instanceOf,
54 (is_object($instance) ? get_class($instance) : gettype($instance))
55 ));
59 /**
60 * Validate the plugin is of the expected type (v2).
62 * Proxies to `validate()`.
64 * @param mixed $plugin
65 * @throws Exception\RuntimeException if invalid
67 public function validatePlugin($plugin)
69 try {
70 $this->validate($plugin);
71 } catch (InvalidServiceException $e) {
72 throw new Exception\RuntimeException($e->getMessage(), $e->getCode(), $e);