Code Coverage
 
Lines
Functions and Methods
Classes and Traits
Total
0.00% covered (danger)
0.00%
0 / 7
0.00% covered (danger)
0.00%
0 / 3
CRAP
0.00% covered (danger)
0.00%
0 / 1
factory
0.00% covered (danger)
0.00%
0 / 7
0.00% covered (danger)
0.00%
0 / 3
30
0.00% covered (danger)
0.00%
0 / 1
 __construct
0.00% covered (danger)
0.00%
0 / 2
0.00% covered (danger)
0.00%
0 / 1
6
 register
0.00% covered (danger)
0.00%
0 / 2
0.00% covered (danger)
0.00%
0 / 1
2
 get
0.00% covered (danger)
0.00%
0 / 3
0.00% covered (danger)
0.00%
0 / 1
6
1<?php
2/**
3 *
4 * This file is part of the phpBB Forum Software package.
5 *
6 * @copyright (c) phpBB Limited <https://www.phpbb.com>
7 * @license GNU General Public License, version 2 (GPL-2.0)
8 *
9 * For full copyright and license information, please see
10 * the docs/CREDITS.txt file.
11 *
12 */
13
14namespace phpbb\install\helper\file_updater;
15
16use phpbb\di\service_collection;
17use phpbb\install\exception\file_updater_failure_exception;
18
19/**
20 * File updater factory
21 */
22class factory
23{
24    /**
25     * @var array
26     */
27    protected $file_updaters;
28
29    /**
30     * Constructor
31     *
32     * @param service_collection $collection    File updater service collection
33     */
34    public function __construct(service_collection $collection)
35    {
36        foreach ($collection as $service)
37        {
38            $this->register($service);
39        }
40    }
41
42    /**
43     * Register updater object
44     *
45     * @param file_updater_interface $updater    Updater object
46     */
47    public function register(file_updater_interface $updater)
48    {
49        $name = $updater->get_method_name();
50        $this->file_updaters[$name] = $updater;
51    }
52
53    /**
54     * Returns file updater object
55     *
56     * @param string $name    Name of the updater method
57     *
58     * @throws file_updater_failure_exception    When the specified file updater does not exist
59     */
60    public function get($name)
61    {
62        if (!isset($this->file_updaters[$name]))
63        {
64            throw new file_updater_failure_exception();
65        }
66
67        return $this->file_updaters[$name];
68    }
69}