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 storage adapters
17 *
18 * Enforces that adapters retrieved are instances of
19 * StorageInterface. Additionally, it registers a number of default
20 * adapters available.
21 */
22class AdapterPluginManager extends AbstractPluginManager
23{
24    /**
25     * Default set of adapters
26     *
27     * @var array
28     */
29    protected $invokableClasses = array(
30        'apc'            => 'Zend\Cache\Storage\Adapter\Apc',
31        'blackhole'      => 'Zend\Cache\Storage\Adapter\BlackHole',
32        'dba'            => 'Zend\Cache\Storage\Adapter\Dba',
33        'filesystem'     => 'Zend\Cache\Storage\Adapter\Filesystem',
34        'memcache'       => 'Zend\Cache\Storage\Adapter\Memcache',
35        'memcached'      => 'Zend\Cache\Storage\Adapter\Memcached',
36        'memory'         => 'Zend\Cache\Storage\Adapter\Memory',
37        'mongodb'        => 'Zend\Cache\Storage\Adapter\MongoDb',
38        'redis'          => 'Zend\Cache\Storage\Adapter\Redis',
39        'session'        => 'Zend\Cache\Storage\Adapter\Session',
40        'xcache'         => 'Zend\Cache\Storage\Adapter\XCache',
41        'wincache'       => 'Zend\Cache\Storage\Adapter\WinCache',
42        'zendserverdisk' => 'Zend\Cache\Storage\Adapter\ZendServerDisk',
43        'zendservershm'  => 'Zend\Cache\Storage\Adapter\ZendServerShm',
44    );
45
46    /**
47     * Do not share by default
48     *
49     * @var array
50     */
51    protected $shareByDefault = false;
52
53    /**
54     * Validate the plugin
55     *
56     * Checks that the adapter loaded is an instance of StorageInterface.
57     *
58     * @param  mixed $plugin
59     * @return void
60     * @throws Exception\RuntimeException if invalid
61     */
62    public function validatePlugin($plugin)
63    {
64        if ($plugin instanceof StorageInterface) {
65            // we're okay
66            return;
67        }
68
69        throw new Exception\RuntimeException(sprintf(
70            'Plugin of type %s is invalid; must implement %s\StorageInterface',
71            (is_object($plugin) ? get_class($plugin) : gettype($plugin)),
72            __NAMESPACE__
73        ));
74    }
75}
76