1<?php 2/** 3 * Zend Framework (http://framework.zend.com/) 4 * 5 * @link http://github.com/zendframework/zf2 for the canonical source repository 6 * @copyright Copyright (c) 2005-2015 Zend Technologies USA Inc. (http://www.zend.com) 7 * @license http://framework.zend.com/license/new-bsd New BSD License 8 */ 9 10namespace Zend\Cache\Storage; 11 12use Zend\Cache\Exception; 13use Zend\ServiceManager\AbstractPluginManager; 14 15/** 16 * Plugin manager implementation for cache plugins 17 * 18 * Enforces that plugins retrieved are instances of 19 * Plugin\PluginInterface. Additionally, it registers a number of default 20 * plugins available. 21 */ 22class PluginManager extends AbstractPluginManager 23{ 24 /** 25 * Default set of plugins 26 * 27 * @var array 28 */ 29 protected $invokableClasses = array( 30 'clearexpiredbyfactor' => 'Zend\Cache\Storage\Plugin\ClearExpiredByFactor', 31 'exceptionhandler' => 'Zend\Cache\Storage\Plugin\ExceptionHandler', 32 'ignoreuserabort' => 'Zend\Cache\Storage\Plugin\IgnoreUserAbort', 33 'optimizebyfactor' => 'Zend\Cache\Storage\Plugin\OptimizeByFactor', 34 'serializer' => 'Zend\Cache\Storage\Plugin\Serializer', 35 ); 36 37 /** 38 * Do not share by default 39 * 40 * @var array 41 */ 42 protected $shareByDefault = false; 43 44 /** 45 * Validate the plugin 46 * 47 * Checks that the plugin loaded is an instance of Plugin\PluginInterface. 48 * 49 * @param mixed $plugin 50 * @return void 51 * @throws Exception\RuntimeException if invalid 52 */ 53 public function validatePlugin($plugin) 54 { 55 if ($plugin instanceof Plugin\PluginInterface) { 56 // we're okay 57 return; 58 } 59 60 throw new Exception\RuntimeException(sprintf( 61 'Plugin of type %s is invalid; must implement %s\Plugin\PluginInterface', 62 (is_object($plugin) ? get_class($plugin) : gettype($plugin)), 63 __NAMESPACE__ 64 )); 65 } 66} 67