Psr0::__construct()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 3
rs 10
cc 1
eloc 2
nc 1
nop 1
1
<?php
2
3
namespace Corpus\Autoloader;
4
5
/**
6
 * Implementation of a PSR-0 Autoloader ignoring the Zend _ nonsense.
7
 *
8
 * <code>
9
 * spl_autoload_register( new Psr0('/vendor/path/blah') );
10
 * </code>
11
 *
12
 * @package Corpus\Autoloader
13
 */
14
class Psr0 {
15
16
	/**
17
	 * @var string
18
	 */
19
	protected $path;
20
21
	/**
22
	 * @param string $path Root path
23
	 */
24
	public function __construct( $path ) {
25
		$this->path = rtrim($path, DIRECTORY_SEPARATOR);
26
	}
27
28
	/**
29
	 * @param string $path
30
	 * @return string
31
	 */
32
	protected final function trimSlashes( $path ) {
33
		return trim($path, ' /\\');
34
	}
35
36
	/**
37
	 * @param $class
38
	 * @return bool|string
39
	 */
40
	public function __invoke( $class ) {
41
		$class       = $this->trimSlashes($class);
42
		$class_parts = explode('\\', $class);
43
44
		$filename = $this->path . DIRECTORY_SEPARATOR . implode(DIRECTORY_SEPARATOR, $class_parts) . ".php";
45
46
		if( file_exists($filename) ) {
47
			require($filename);
48
		}
49
50
		return $filename;
51
	}
52
53
54
}