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