Autoloader::__construct()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 5

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
nc 1
nop 2
dl 0
loc 5
rs 10
c 0
b 0
f 0
1
<?php
2
/**
3
 * Webino (http://webino.sk/)
4
 *
5
 * @link        https://github.com/webino/WebinoDev/ for the canonical source repository
6
 * @copyright   Copyright (c) 2014-2017 Webino, s. r. o. (http://webino.sk/)
7
 * @license     BSD-3-Clause
8
 */
9
10
namespace WebinoDev\Test;
11
12
use RuntimeException;
13
14
/**
15
 * Tests resources auto loader
16
 */
17
class Autoloader
18
{
19
    /**
20
     * @var string
21
     */
22
    protected $dir;
23
24
    /**
25
     * @var string
26
     */
27
    protected $namespace;
28
29
    /**
30
     * @param string $dir
31
     * @param string $namespace
32
     */
33
    public function __construct($dir, $namespace)
34
    {
35
        $this->dir       = (string) $dir;
36
        $this->namespace = (string) $namespace;
37
    }
38
39
    /**
40
     * @param object $loader Autoloader
41
     * @trows RuntimeException
42
     */
43
    public function __invoke($loader)
44
    {
45
        if (empty($loader)) {
46
            throw new RuntimeException('Unable to load. Run `php composer.phar install`.');
47
        }
48
49
        $loader->add('Application', $this->dir . '/src');
50
        $loader->add($this->namespace, $this->dir . '/src');
51
        $loader->add($this->namespace, $this->dir . '/../../src');
52
        $loader->add($this->namespace, $this->dir . '/../functional');
53
        $loader->add($this->namespace, $this->dir . '/../selenium');
54
        $loader->add($this->namespace, $this->dir . '/..');
55
56
        $this->initDevLoader();
57
    }
58
59
    /**
60
     * Initialize Webino-Devkit vendor autoloader
61
     */
62
    protected function initDevLoader()
63
    {
64
        $loader = @include '/var/lib/webino/php/vendor/autoload.php';
65
        if (empty($loader)) {
66
            throw new RuntimeException(
67
                'Unable to load the Webino-Devkit. Run `wget https://get.webino.org/devkit -qO - | sh`.'
68
            );
69
        }
70
71
        $loader->unregister();
72
        $loader->register(false);
73
    }
74
}
75