| 1 |
<?php |
|---|
| 2 |
|
|---|
| 3 |
|
|---|
| 4 |
|
|---|
| 5 |
|
|---|
| 6 |
|
|---|
| 7 |
|
|---|
| 8 |
|
|---|
| 9 |
|
|---|
| 10 |
|
|---|
| 11 |
|
|---|
| 12 |
|
|---|
| 13 |
|
|---|
| 14 |
|
|---|
| 15 |
|
|---|
| 16 |
|
|---|
| 17 |
|
|---|
| 18 |
|
|---|
| 19 |
|
|---|
| 20 |
class sfAutoloadConfigHandler extends sfYamlConfigHandler |
|---|
| 21 |
{ |
|---|
| 22 |
|
|---|
| 23 |
* Executes this configuration handler. |
|---|
| 24 |
* |
|---|
| 25 |
* @param array An array of absolute filesystem path to a configuration file |
|---|
| 26 |
* |
|---|
| 27 |
* @return string Data to be written to a cache file |
|---|
| 28 |
* |
|---|
| 29 |
* @throws sfConfigurationException If a requested configuration file does not exist or is not readable |
|---|
| 30 |
* @throws sfParseException If a requested configuration file is improperly formatted |
|---|
| 31 |
*/ |
|---|
| 32 |
public function execute($configFiles) |
|---|
| 33 |
{ |
|---|
| 34 |
|
|---|
| 35 |
$categories = array('required_categories' => array('autoload')); |
|---|
| 36 |
|
|---|
| 37 |
$this->initialize($categories); |
|---|
| 38 |
|
|---|
| 39 |
|
|---|
| 40 |
$myConfig = $this->parseYamls($configFiles); |
|---|
| 41 |
|
|---|
| 42 |
|
|---|
| 43 |
$data = array(); |
|---|
| 44 |
|
|---|
| 45 |
|
|---|
| 46 |
foreach ($myConfig['autoload'] as $name => $entry) |
|---|
| 47 |
{ |
|---|
| 48 |
if (isset($entry['name'])) |
|---|
| 49 |
{ |
|---|
| 50 |
$data[] = sprintf("\n// %s", $entry['name']); |
|---|
| 51 |
} |
|---|
| 52 |
|
|---|
| 53 |
|
|---|
| 54 |
if (isset($entry['files'])) |
|---|
| 55 |
{ |
|---|
| 56 |
|
|---|
| 57 |
foreach ($entry['files'] as $class => $path) |
|---|
| 58 |
{ |
|---|
| 59 |
$path = $this->replaceConstants($path); |
|---|
| 60 |
|
|---|
| 61 |
$data[] = sprintf("'%s' => '%s',", $class, $path); |
|---|
| 62 |
} |
|---|
| 63 |
} |
|---|
| 64 |
else |
|---|
| 65 |
{ |
|---|
| 66 |
|
|---|
| 67 |
$ext = isset($entry['ext']) ? $entry['ext'] : '.php'; |
|---|
| 68 |
$path = $entry['path']; |
|---|
| 69 |
|
|---|
| 70 |
$path = $this->replaceConstants($path); |
|---|
| 71 |
$path = $this->replacePath($path); |
|---|
| 72 |
|
|---|
| 73 |
|
|---|
| 74 |
require_once(sfConfig::get('sf_symfony_lib_dir').'/util/sfFinder.class.php'); |
|---|
| 75 |
$finder = sfFinder::type('file')->ignore_version_control()->name('*'.$ext); |
|---|
| 76 |
|
|---|
| 77 |
|
|---|
| 78 |
$recursive = ((isset($entry['recursive'])) ? $entry['recursive'] : false); |
|---|
| 79 |
if (!$recursive) |
|---|
| 80 |
{ |
|---|
| 81 |
$finder->maxdepth(0); |
|---|
| 82 |
} |
|---|
| 83 |
|
|---|
| 84 |
|
|---|
| 85 |
if (isset($entry['exclude']) && is_array($entry['exclude'])) |
|---|
| 86 |
{ |
|---|
| 87 |
$finder->prune($entry['exclude'])->discard($entry['exclude']); |
|---|
| 88 |
} |
|---|
| 89 |
|
|---|
| 90 |
if ($matches = glob($path)) |
|---|
| 91 |
{ |
|---|
| 92 |
$files = $finder->in($matches); |
|---|
| 93 |
} |
|---|
| 94 |
else |
|---|
| 95 |
{ |
|---|
| 96 |
$files = array(); |
|---|
| 97 |
} |
|---|
| 98 |
|
|---|
| 99 |
$regex = '~^\s*(?:abstract\s+|final\s+)?(?:class|interface)\s+(\w+)~mi'; |
|---|
| 100 |
foreach ($files as $file) |
|---|
| 101 |
{ |
|---|
| 102 |
preg_match_all($regex, file_get_contents($file), $classes); |
|---|
| 103 |
foreach ($classes[1] as $class) |
|---|
| 104 |
{ |
|---|
| 105 |
$prefix = ''; |
|---|
| 106 |
if (isset($entry['prefix'])) |
|---|
| 107 |
{ |
|---|
| 108 |
|
|---|
| 109 |
preg_match('~^'.str_replace('\*', '(.+?)', preg_quote(str_replace('/', DIRECTORY_SEPARATOR, $path), '~')).'~', str_replace('/', DIRECTORY_SEPARATOR, $file), $match); |
|---|
| 110 |
if (isset($match[$entry['prefix']])) |
|---|
| 111 |
{ |
|---|
| 112 |
$prefix = $match[$entry['prefix']].'/'; |
|---|
| 113 |
} |
|---|
| 114 |
} |
|---|
| 115 |
|
|---|
| 116 |
$data[] = sprintf("'%s%s' => '%s',", $prefix, $class, str_replace('\\', '\\\\', $file)); |
|---|
| 117 |
} |
|---|
| 118 |
} |
|---|
| 119 |
} |
|---|
| 120 |
} |
|---|
| 121 |
|
|---|
| 122 |
|
|---|
| 123 |
$retval = sprintf("<?php\n". |
|---|
| 124 |
"// auto-generated by sfAutoloadConfigHandler\n". |
|---|
| 125 |
"// date: %s\nreturn array(\n%s\n);\n", |
|---|
| 126 |
date('Y/m/d H:i:s'), implode("\n", $data)); |
|---|
| 127 |
|
|---|
| 128 |
return $retval; |
|---|
| 129 |
} |
|---|
| 130 |
} |
|---|
| 131 |
|
|---|