-
Notifications
You must be signed in to change notification settings - Fork 13
/
Brush.php
79 lines (67 loc) · 1.7 KB
/
Brush.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
<?php
/**
* Brush is a complete object-oriented PHP wrapper for the Pastebin API.
* @author George Brighton
* @link https://github.com/gebn/Brush
*/
namespace Brush {
// let Crackle initialise itself
require 'Libraries/Crackle/Crackle.php';
use \Brush\Exceptions\DependencyException;
/*
* This file should be included using `require[_once]` before Brush is used.
*/
Brush::load();
/**
* Sets up the environment required by Brush.
* @author George Brighton
*/
final class Brush {
/**
* This version of Brush.
* @var string
*/
const VERSION = '1.2.0';
/**
* This class should not be instantiated.
*/
private function __construct() {}
/**
* Readies Brush for use.
*/
public static function load() {
static $loaded = false;
// we only want to initialise once
if (!$loaded) {
self::initialise();
$loaded = true;
}
}
/**
* Carries out everything needed to get Brush up and running.
*/
private static function initialise() {
self::registerAutoloader();
self::checkRequirements();
}
/**
* Adds Brush's autoloader function.
*/
private static function registerAutoloader() {
spl_autoload_register(function($qualified) {
if (substr($qualified, 0, 6) == 'Brush\\') {
require str_replace('\\', DIRECTORY_SEPARATOR, substr($qualified, 6)) . '.php';
}
}, true);
}
/**
* Ensures this installation of PHP meets Brush's minimum requirements.
* @throws \Brush\Exceptions\DependencyException If any requirement is not met.
*/
private static function checkRequirements() {
if (version_compare(PHP_VERSION, '5.3.0', '<')) {
throw new DependencyException('Brush requires PHP 5.3.0 or later.');
}
}
}
}