forked from zendframework/zendframework
-
Notifications
You must be signed in to change notification settings - Fork 0
/
createAutoloadTestClasses.php
37 lines (33 loc) · 1.16 KB
/
createAutoloadTestClasses.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
<?php
/**
* createAutoloadTestClasses.php
*
* A script for creating a hierarchy of classes for use with testing
* autoloading. Each directory has classes from a to p; additional classes are
* generated 2 levels deep, giving a total of 16^3 classes to use in
* autoloading tests.
*/
function createClasses($depth, $namespace)
{
foreach (range('a', 'p') as $letter) {
// Create content for namespaced class
$content = "<?php\nnamespace $namespace;\nclass $letter { }";
// Write content to disk
$dir = str_replace('\\', DIRECTORY_SEPARATOR, $namespace);
file_put_contents(
$dir . DIRECTORY_SEPARATOR . $letter . '.php',
$content
);
// If we still have depth, recurse and create more classes using the
// current letter as a sub-namespace.
if ($depth > 0) {
$childDir = $dir . DIRECTORY_SEPARATOR . $letter;
mkdir($childDir);
createClasses($depth - 1, $namespace . '\\' . $letter);
}
}
}
// Use 'test' as the top-level namespace, and set a depth of "2" (will provide
// 3 levels of classes).
mkdir('test');
createClasses(2, 'test');