Details | Last modification | View Log | RSS feed
Rev | Author | Line No. | Line |
---|---|---|---|
39 | PointedEar | 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-2013 Zend Technologies USA Inc. (http://www.zend.com) |
||
7 | * @license http://framework.zend.com/license/new-bsd New BSD License |
||
8 | */ |
||
9 | |||
10 | namespace Zend\I18n\Translator; |
||
11 | |||
12 | use Zend\I18n\Exception; |
||
13 | use Zend\ServiceManager\AbstractPluginManager; |
||
14 | |||
15 | /** |
||
16 | * Plugin manager implementation for translation loaders. |
||
17 | * |
||
18 | * Enforces that loaders retrieved are either instances of |
||
19 | * Loader\FileLoaderInterface or Loader\RemoteLoaderInterface. Additionally, |
||
20 | * it registers a number of default loaders. |
||
21 | */ |
||
22 | class LoaderPluginManager extends AbstractPluginManager |
||
23 | { |
||
24 | /** |
||
25 | * Default set of loaders. |
||
26 | * |
||
27 | * @var array |
||
28 | */ |
||
29 | protected $invokableClasses = array( |
||
30 | 'gettext' => 'Zend\I18n\Translator\Loader\Gettext', |
||
31 | 'ini' => 'Zend\I18n\Translator\Loader\Ini', |
||
32 | 'phparray' => 'Zend\I18n\Translator\Loader\PhpArray', |
||
33 | ); |
||
34 | |||
35 | /** |
||
36 | * Validate the plugin. |
||
37 | * |
||
38 | * Checks that the filter loaded is an instance of |
||
39 | * Loader\FileLoaderInterface or Loader\RemoteLoaderInterface. |
||
40 | * |
||
41 | * @param mixed $plugin |
||
42 | * @return void |
||
43 | * @throws Exception\RuntimeException if invalid |
||
44 | */ |
||
45 | public function validatePlugin($plugin) |
||
46 | { |
||
47 | if ($plugin instanceof Loader\FileLoaderInterface || $plugin instanceof Loader\RemoteLoaderInterface) { |
||
48 | // we're okay |
||
49 | return; |
||
50 | } |
||
51 | |||
52 | throw new Exception\RuntimeException(sprintf( |
||
53 | 'Plugin of type %s is invalid; must implement %s\Loader\FileLoaderInterface or %s\Loader\RemoteLoaderInterface', |
||
54 | (is_object($plugin) ? get_class($plugin) : gettype($plugin)), |
||
55 | __NAMESPACE__ |
||
56 | )); |
||
57 | } |
||
58 | } |