Skip to content

Commit 5e39e80

Browse files
committed
Add autoload.php
1 parent 852c83b commit 5e39e80

5 files changed

Lines changed: 88 additions & 2 deletions

File tree

autoload.php

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
<?php
2+
3+
/**
4+
* CodeMommy ConfigPHP
5+
* @author Candison November <www.kandisheng.com>
6+
*/
7+
8+
if (!class_exists('autoloadDirectory')) {
9+
/**
10+
* Autoload Directory
11+
* @param string $directory
12+
* @param string $namespaceRoot
13+
*/
14+
function autoloadDirectory($directory = '.', $namespaceRoot = '')
15+
{
16+
spl_autoload_register(function ($className) use ($directory, $namespaceRoot) {
17+
$directory = str_replace(array('/', '\\'), DIRECTORY_SEPARATOR, $directory);
18+
$directory = rtrim($directory, '/\\');
19+
$namespaceRoot = str_replace(array('/', '\\'), DIRECTORY_SEPARATOR, $namespaceRoot);
20+
$namespaceRoot = trim($namespaceRoot, '/\\');
21+
$className = str_replace(array('/', '\\'), DIRECTORY_SEPARATOR, $className);
22+
$className = trim($className, '/\\');
23+
if (substr($className, 0, strlen($namespaceRoot)) == $namespaceRoot) {
24+
$className = substr($className, strlen($namespaceRoot));
25+
$className = ltrim($className, '/\\');
26+
}
27+
$extensionList = array('php', 'class.php');
28+
foreach ($extensionList as $extension) {
29+
$file = $directory . DIRECTORY_SEPARATOR . $className . '.' . $extension;
30+
if (is_file($file) && is_readable($file)) {
31+
require_once($file);
32+
}
33+
}
34+
});
35+
}
36+
}
37+
38+
autoloadDirectory(sprintf('%s%ssource', __DIR__, DIRECTORY_SEPARATOR), 'CodeMommy\ConfigPHP');
39+
autoloadDirectory(sprintf('%s%sinterface', __DIR__, DIRECTORY_SEPARATOR), 'CodeMommy\ConfigPHP');

composer.json

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,10 @@
2424
],
2525
"autoload": {
2626
"psr-4": {
27-
"CodeMommy\\ConfigPHP\\": "source/"
27+
"CodeMommy\\ConfigPHP\\": [
28+
"interface/",
29+
"source/"
30+
]
2831
}
2932
},
3033
"autoload-dev": {

interface/ConfigInterface.php

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
<?php
2+
3+
/**
4+
* CodeMommy ConfigPHP
5+
* @author Candison November <www.kandisheng.com>
6+
*/
7+
8+
namespace CodeMommy\ConfigPHP;
9+
10+
/**
11+
* Interface ConfigInterface
12+
* @package CodeMommy\ConfigPHP
13+
*/
14+
interface ConfigInterface
15+
{
16+
/**
17+
* ConfigInterface constructor.
18+
*/
19+
public function __construct();
20+
21+
/**
22+
* Add Directory
23+
* @param string $directory
24+
* @return mixed
25+
*/
26+
public static function addDirectory($directory = '.');
27+
28+
/**
29+
* Clear Cache
30+
* @return mixed
31+
*/
32+
public static function clearCache();
33+
34+
/**
35+
* Get
36+
* @param $key
37+
* @param null $default
38+
* @return mixed
39+
*/
40+
public static function get($key, $default = null);
41+
}

phpunit.xml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
</testsuites>
99
<filter>
1010
<whitelist processUncoveredFilesFromWhitelist="true">
11+
<directory suffix=".php">./interface</directory>
1112
<directory suffix=".php">./source</directory>
1213
</whitelist>
1314
</filter>

source/Config.php

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,14 +13,16 @@
1313
* Class Config
1414
* @package CodeMommy\ConfigPHP
1515
*/
16-
class Config
16+
class Config implements ConfigInterface
1717
{
1818
/**
19+
* Config Directory
1920
* @var array
2021
*/
2122
private static $configDirectory = array();
2223

2324
/**
25+
* Cache
2426
* @var array
2527
*/
2628
private static $cache = array();

0 commit comments

Comments
 (0)