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