Newer
Older
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
<?php
/**
* Commonly used classes used in the Minimalistic package.
*
* @author Taddeus Kroes
* @version 1.0
* @date 13-07-2012
* @package Minimalistic
*/
namespace Minimalistic;
require_once 'logger.php';
/**
* Base class for instantiable classes in the Minimalistic package.
*
* The base class defines a static 'create' method that acts as a chainable
* shortcut for the class constructor.
*
* @package Minimalistic
*/
abstract class Base {
/**
* Create a new object of the called class.
*
* This function provides a chainable constructor, which is not possible
* using plain PHP code.
*
* @returns mixed
*/
final static function create(/* [ arg0 [ , ... ] ] */) {
$args = func_get_args();
$class = get_called_class();
$rc = new \ReflectionClass($class);
return $rc->newInstanceArgs($args);
}
}
/**
* Exception, thrown when a required file does not exist.
*
* @package Minimalistic
*/
class FileNotFoundError extends \RuntimeException {
/**
* Create a new FileNotFoundError instance.
*
* Sets an error message of the form 'File "path/to/file.php" does not exist.'.
*
* @param string $path Path to the file that does not exist.
*/
function __construct($path) {
$this->message = sprintf('File "%s" does not exist.', $path);
}
}
/**
* Format a string of the form 'foo %(bar)' with given parameters like array('bar' => 'some value').
*
* @param string $format The string to format.
* @param array $params An associative array with parameters that are used in the format.
*/
function asprintf($format, array $params) {
return preg_replace_callback(
'/%\(([a-z-_ ]*)\)/i',
function ($matches) use ($params) {
return (string)$params[$matches[1]];
},
$format
);
}
?>