1: <?php
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: class mpClassMapFileCreator {
31:
32: 33: 34: 35: 36:
37: protected $_template = '';
38:
39: 40: 41: 42: 43:
44: protected $_data = '';
45:
46: 47: 48:
49: public function __construct() {
50: $this->_template = trim('
51: <?php
52: /**
53: {DESCRIPTION}
54: *
55: * @package {PACKAGE}
56: * @subpackage {SUBPACKAGE}
57: * @version {VERSION}
58: * @author {AUTHOR}
59: * @copyright {COPYRIGHT}
60: * @license {LICENSE}
61: */
62:
63: {CONTENT}
64: ');
65: $this->_data = new stdClass();
66: $this->_data->content = '';
67: $this->_data->description = trim('
68: * Autoloader classmap file. Contains all available classes/interfaces and
69: * related class files.
70: *
71: * NOTES:
72: * - Don\'t edit this file manually!
73: * - It was generated by ' . __CLASS__ . '
74: * - Use ' . __CLASS__ . ' again, if you want to regenerate this file
75: *');
76:
77: $this->_data->package = __CLASS__;
78: $this->_data->subpackage = 'Classmap';
79: $this->_data->version = '0.1';
80: $this->_data->author = 'System';
81: $this->_data->copyright = 'Copyright (c) 2009-2010 Murat Purc (http://www.purc.de)';
82: $this->_data->license = 'http://www.gnu.org/licenses/gpl-2.0.html - GNU General Public License, version 2';
83: }
84:
85: 86: 87: 88: 89: 90: 91: 92: 93: 94:
95: public function create(array $data, $file) {
96: $this->_createClassMap($data);
97:
98: return (bool) file_put_contents($file, $this->_renderTemplate());
99: }
100:
101: 102: 103: 104: 105: 106:
107: protected function _createClassMap(array $data) {
108: $classMapTpl = "\r\nreturn array(\r\n%s\r\n);\r\n";
109: $classMapContent = '';
110: foreach ($data as $classToken => $path) {
111: $classMapContent .= sprintf(" '%s' => '%s',\r\n", addslashes($classToken), addslashes($path));
112: }
113: $classMapContent = substr($classMapContent, 0, -3);
114:
115: $this->_data->content .= sprintf($classMapTpl, $classMapContent);
116: }
117:
118: 119: 120: 121: 122: 123:
124: protected function _renderTemplate() {
125: $template = $this->_template;
126: foreach ($this->_data as $name => $value) {
127: $template = str_replace('{' . strtoupper($name) . '}', $value, $template);
128: }
129:
130: return $template;
131: }
132:
133: }
134: