@@ -2,179 +2,179 @@ |
||
2 | 2 | |
3 | 3 | namespace CloudControl\Cms\components { |
4 | 4 | |
5 | - use CloudControl\Cms\cc\Application; |
|
6 | - use CloudControl\Cms\cc\Request; |
|
7 | - use CloudControl\Cms\storage\Storage; |
|
5 | + use CloudControl\Cms\cc\Application; |
|
6 | + use CloudControl\Cms\cc\Request; |
|
7 | + use CloudControl\Cms\storage\Storage; |
|
8 | 8 | |
9 | - class BaseComponent implements Component |
|
10 | - { |
|
11 | - /** |
|
12 | - * @var string |
|
13 | - */ |
|
14 | - protected $template; |
|
15 | - /** |
|
16 | - * @var \CloudControl\Cms\cc\Request |
|
17 | - */ |
|
18 | - protected $request; |
|
19 | - /** |
|
20 | - * @var Storage |
|
21 | - */ |
|
22 | - protected $storage; |
|
23 | - /** |
|
24 | - * @var mixed |
|
25 | - */ |
|
26 | - protected $renderedContent; |
|
27 | - /** |
|
28 | - * @var array |
|
29 | - */ |
|
30 | - protected $parameters = array(); |
|
31 | - /*** |
|
9 | + class BaseComponent implements Component |
|
10 | + { |
|
11 | + /** |
|
12 | + * @var string |
|
13 | + */ |
|
14 | + protected $template; |
|
15 | + /** |
|
16 | + * @var \CloudControl\Cms\cc\Request |
|
17 | + */ |
|
18 | + protected $request; |
|
19 | + /** |
|
20 | + * @var Storage |
|
21 | + */ |
|
22 | + protected $storage; |
|
23 | + /** |
|
24 | + * @var mixed |
|
25 | + */ |
|
26 | + protected $renderedContent; |
|
27 | + /** |
|
28 | + * @var array |
|
29 | + */ |
|
30 | + protected $parameters = array(); |
|
31 | + /*** |
|
32 | 32 | * @var \stdClass |
33 | 33 | */ |
34 | - protected $matchedSitemapItem; |
|
34 | + protected $matchedSitemapItem; |
|
35 | 35 | |
36 | - /** |
|
37 | - * BaseComponent constructor. |
|
38 | - * |
|
39 | - * @param string $template |
|
40 | - * @param Request $request |
|
41 | - * @param array $parameters |
|
42 | - * @param $matchedSitemapItem |
|
43 | - */ |
|
44 | - public function __construct($template = '', Request $request, $parameters = array(), $matchedSitemapItem) |
|
45 | - { |
|
46 | - $this->template = $template; |
|
47 | - $this->request = $request; |
|
48 | - $this->parameters = (array)$parameters; |
|
49 | - $this->matchedSitemapItem = $matchedSitemapItem; |
|
50 | - } |
|
36 | + /** |
|
37 | + * BaseComponent constructor. |
|
38 | + * |
|
39 | + * @param string $template |
|
40 | + * @param Request $request |
|
41 | + * @param array $parameters |
|
42 | + * @param $matchedSitemapItem |
|
43 | + */ |
|
44 | + public function __construct($template = '', Request $request, $parameters = array(), $matchedSitemapItem) |
|
45 | + { |
|
46 | + $this->template = $template; |
|
47 | + $this->request = $request; |
|
48 | + $this->parameters = (array)$parameters; |
|
49 | + $this->matchedSitemapItem = $matchedSitemapItem; |
|
50 | + } |
|
51 | 51 | |
52 | - /** |
|
53 | - * Hook for implementation in derived classes |
|
54 | - * |
|
55 | - * @param Storage $storage |
|
56 | - */ |
|
57 | - public function run(Storage $storage) |
|
58 | - { |
|
59 | - $this->storage = $storage; |
|
60 | - } |
|
52 | + /** |
|
53 | + * Hook for implementation in derived classes |
|
54 | + * |
|
55 | + * @param Storage $storage |
|
56 | + */ |
|
57 | + public function run(Storage $storage) |
|
58 | + { |
|
59 | + $this->storage = $storage; |
|
60 | + } |
|
61 | 61 | |
62 | - /** |
|
63 | - * Renders the template |
|
64 | - * |
|
65 | - * @param null|Application $application |
|
66 | - * |
|
67 | - * @throws \Exception |
|
68 | - */ |
|
69 | - public function render($application = null) |
|
70 | - { |
|
71 | - $this->renderedContent = $this->renderTemplate($this->template, true, $application); |
|
72 | - } |
|
62 | + /** |
|
63 | + * Renders the template |
|
64 | + * |
|
65 | + * @param null|Application $application |
|
66 | + * |
|
67 | + * @throws \Exception |
|
68 | + */ |
|
69 | + public function render($application = null) |
|
70 | + { |
|
71 | + $this->renderedContent = $this->renderTemplate($this->template, true, $application); |
|
72 | + } |
|
73 | 73 | |
74 | - /** |
|
75 | - * Returns the rendered content |
|
76 | - * |
|
77 | - * @return mixed |
|
78 | - */ |
|
79 | - public function get() |
|
80 | - { |
|
81 | - return $this->renderedContent; |
|
82 | - } |
|
74 | + /** |
|
75 | + * Returns the rendered content |
|
76 | + * |
|
77 | + * @return mixed |
|
78 | + */ |
|
79 | + public function get() |
|
80 | + { |
|
81 | + return $this->renderedContent; |
|
82 | + } |
|
83 | 83 | |
84 | - /** |
|
85 | - * Decoupled render method, for usage in derived classes |
|
86 | - * |
|
87 | - * @param string $template |
|
88 | - * |
|
89 | - * @param bool $obClean |
|
90 | - * @param null | Application $application |
|
91 | - * |
|
92 | - * @return string |
|
93 | - * @throws \Exception |
|
94 | - */ |
|
95 | - public function renderTemplate($template = '', $obClean = true, $application = null) |
|
96 | - { |
|
97 | - $templatePath = $this->getTemplatePath($template, $application); |
|
98 | - if (realpath($templatePath) !== false) { |
|
99 | - if ($obClean) { |
|
100 | - ob_clean(); |
|
101 | - } |
|
102 | - $this->parameters['request'] = $this->request; |
|
103 | - if ($application !== null) { |
|
104 | - $acParameters = $application->getAllApplicationComponentParameters(); |
|
105 | - foreach ($acParameters as $parameters) { |
|
106 | - extract($parameters); |
|
107 | - } |
|
108 | - } |
|
109 | - extract($this->parameters); |
|
110 | - include($templatePath); |
|
111 | - return ob_get_contents(); |
|
112 | - } else { |
|
113 | - if ($template !== null) { // If template is null, its a application component, which doesnt have a template |
|
114 | - throw new \Exception('Couldnt find template ' . $templatePath); |
|
115 | - } |
|
116 | - } |
|
117 | - } |
|
84 | + /** |
|
85 | + * Decoupled render method, for usage in derived classes |
|
86 | + * |
|
87 | + * @param string $template |
|
88 | + * |
|
89 | + * @param bool $obClean |
|
90 | + * @param null | Application $application |
|
91 | + * |
|
92 | + * @return string |
|
93 | + * @throws \Exception |
|
94 | + */ |
|
95 | + public function renderTemplate($template = '', $obClean = true, $application = null) |
|
96 | + { |
|
97 | + $templatePath = $this->getTemplatePath($template, $application); |
|
98 | + if (realpath($templatePath) !== false) { |
|
99 | + if ($obClean) { |
|
100 | + ob_clean(); |
|
101 | + } |
|
102 | + $this->parameters['request'] = $this->request; |
|
103 | + if ($application !== null) { |
|
104 | + $acParameters = $application->getAllApplicationComponentParameters(); |
|
105 | + foreach ($acParameters as $parameters) { |
|
106 | + extract($parameters); |
|
107 | + } |
|
108 | + } |
|
109 | + extract($this->parameters); |
|
110 | + include($templatePath); |
|
111 | + return ob_get_contents(); |
|
112 | + } else { |
|
113 | + if ($template !== null) { // If template is null, its a application component, which doesnt have a template |
|
114 | + throw new \Exception('Couldnt find template ' . $templatePath); |
|
115 | + } |
|
116 | + } |
|
117 | + } |
|
118 | 118 | |
119 | - /** |
|
120 | - * Alias for renderTemplate for usage to include templates in other templates |
|
121 | - * |
|
122 | - * @param string $template |
|
123 | - * |
|
124 | - * @param array $parameters |
|
125 | - * |
|
126 | - * @return string |
|
127 | - * @throws \Exception |
|
128 | - */ |
|
129 | - public function includeTemplate($template = '', $parameters = array()) |
|
130 | - { |
|
131 | - if (is_array($parameters)) { |
|
132 | - foreach ($parameters as $name => $value) { |
|
133 | - $this->parameters[$name] = $value; |
|
134 | - } |
|
135 | - } |
|
136 | - return $this->renderTemplate($template, false); |
|
137 | - } |
|
119 | + /** |
|
120 | + * Alias for renderTemplate for usage to include templates in other templates |
|
121 | + * |
|
122 | + * @param string $template |
|
123 | + * |
|
124 | + * @param array $parameters |
|
125 | + * |
|
126 | + * @return string |
|
127 | + * @throws \Exception |
|
128 | + */ |
|
129 | + public function includeTemplate($template = '', $parameters = array()) |
|
130 | + { |
|
131 | + if (is_array($parameters)) { |
|
132 | + foreach ($parameters as $name => $value) { |
|
133 | + $this->parameters[$name] = $value; |
|
134 | + } |
|
135 | + } |
|
136 | + return $this->renderTemplate($template, false); |
|
137 | + } |
|
138 | 138 | |
139 | - public function getParameters() |
|
140 | - { |
|
141 | - return $this->parameters; |
|
142 | - } |
|
139 | + public function getParameters() |
|
140 | + { |
|
141 | + return $this->parameters; |
|
142 | + } |
|
143 | 143 | |
144 | - /** |
|
145 | - * @param $template |
|
146 | - * @param null | Application $application |
|
147 | - * @return string |
|
148 | - */ |
|
149 | - protected function getTemplateDir($template, $application = null) |
|
150 | - { |
|
151 | - $templatePath = ''; |
|
152 | - if ($application !== null) { |
|
153 | - $templatePath = $application->getTemplateDir(); |
|
154 | - } |
|
155 | - $templatePath = $templatePath . $template . '.php'; |
|
156 | - return $templatePath; |
|
157 | - } |
|
144 | + /** |
|
145 | + * @param $template |
|
146 | + * @param null | Application $application |
|
147 | + * @return string |
|
148 | + */ |
|
149 | + protected function getTemplateDir($template, $application = null) |
|
150 | + { |
|
151 | + $templatePath = ''; |
|
152 | + if ($application !== null) { |
|
153 | + $templatePath = $application->getTemplateDir(); |
|
154 | + } |
|
155 | + $templatePath = $templatePath . $template . '.php'; |
|
156 | + return $templatePath; |
|
157 | + } |
|
158 | 158 | |
159 | - /** |
|
160 | - * @param $template |
|
161 | - * @param $application |
|
162 | - * @return string |
|
163 | - */ |
|
164 | - private function getTemplatePath($template, $application) |
|
165 | - { |
|
166 | - $templateDir = $this->getTemplateDir($template, $application); |
|
167 | - if ($application !== null) { |
|
168 | - $rootDir = $application->getRootDir(); |
|
169 | - if (strpos($templateDir, $rootDir) === false) { |
|
170 | - $templatePath = $rootDir . DIRECTORY_SEPARATOR . $templateDir; |
|
171 | - } else { |
|
172 | - $templatePath = $templateDir; |
|
173 | - } |
|
174 | - } else { |
|
175 | - $templatePath = $templateDir; |
|
176 | - } |
|
177 | - return $templatePath; |
|
178 | - } |
|
179 | - } |
|
159 | + /** |
|
160 | + * @param $template |
|
161 | + * @param $application |
|
162 | + * @return string |
|
163 | + */ |
|
164 | + private function getTemplatePath($template, $application) |
|
165 | + { |
|
166 | + $templateDir = $this->getTemplateDir($template, $application); |
|
167 | + if ($application !== null) { |
|
168 | + $rootDir = $application->getRootDir(); |
|
169 | + if (strpos($templateDir, $rootDir) === false) { |
|
170 | + $templatePath = $rootDir . DIRECTORY_SEPARATOR . $templateDir; |
|
171 | + } else { |
|
172 | + $templatePath = $templateDir; |
|
173 | + } |
|
174 | + } else { |
|
175 | + $templatePath = $templateDir; |
|
176 | + } |
|
177 | + return $templatePath; |
|
178 | + } |
|
179 | + } |
|
180 | 180 | } |
181 | 181 | \ No newline at end of file |
@@ -45,7 +45,7 @@ discard block |
||
45 | 45 | { |
46 | 46 | $this->template = $template; |
47 | 47 | $this->request = $request; |
48 | - $this->parameters = (array)$parameters; |
|
48 | + $this->parameters = (array) $parameters; |
|
49 | 49 | $this->matchedSitemapItem = $matchedSitemapItem; |
50 | 50 | } |
51 | 51 | |
@@ -111,7 +111,7 @@ discard block |
||
111 | 111 | return ob_get_contents(); |
112 | 112 | } else { |
113 | 113 | if ($template !== null) { // If template is null, its a application component, which doesnt have a template |
114 | - throw new \Exception('Couldnt find template ' . $templatePath); |
|
114 | + throw new \Exception('Couldnt find template '.$templatePath); |
|
115 | 115 | } |
116 | 116 | } |
117 | 117 | } |
@@ -152,7 +152,7 @@ discard block |
||
152 | 152 | if ($application !== null) { |
153 | 153 | $templatePath = $application->getTemplateDir(); |
154 | 154 | } |
155 | - $templatePath = $templatePath . $template . '.php'; |
|
155 | + $templatePath = $templatePath.$template.'.php'; |
|
156 | 156 | return $templatePath; |
157 | 157 | } |
158 | 158 | |
@@ -167,7 +167,7 @@ discard block |
||
167 | 167 | if ($application !== null) { |
168 | 168 | $rootDir = $application->getRootDir(); |
169 | 169 | if (strpos($templateDir, $rootDir) === false) { |
170 | - $templatePath = $rootDir . DIRECTORY_SEPARATOR . $templateDir; |
|
170 | + $templatePath = $rootDir.DIRECTORY_SEPARATOR.$templateDir; |
|
171 | 171 | } else { |
172 | 172 | $templatePath = $templateDir; |
173 | 173 | } |
@@ -11,213 +11,213 @@ |
||
11 | 11 | |
12 | 12 | class CloudControl |
13 | 13 | { |
14 | - public static function run() |
|
15 | - { |
|
16 | - new Application(); |
|
17 | - } |
|
18 | - |
|
19 | - public static function postInstall(Event $event) |
|
20 | - { |
|
21 | - $event->getIO()->write("Post install"); |
|
22 | - self::checkInstall($event); |
|
23 | - } |
|
24 | - |
|
25 | - public static function postUpdate(Event $event) |
|
26 | - { |
|
27 | - $event->getIO()->write("Post update"); |
|
28 | - self::checkInstall($event); |
|
29 | - } |
|
30 | - |
|
31 | - /** |
|
32 | - * @param Event $event |
|
33 | - */ |
|
34 | - private static function checkInstall(Event $event) |
|
35 | - { |
|
36 | - $event->getIO()->write(""); |
|
37 | - $event->getIO()->write("********************************************************"); |
|
38 | - $event->getIO()->write("*** Checking installation of Cloud Control framework ***"); |
|
39 | - $event->getIO()->write("********************************************************"); |
|
40 | - $event->getIO()->write(""); |
|
41 | - |
|
42 | - $vendorDir = $event->getComposer()->getConfig()->get('vendor-dir'); |
|
43 | - $rootDir = realpath($vendorDir . DIRECTORY_SEPARATOR . '..' . DIRECTORY_SEPARATOR); |
|
44 | - |
|
45 | - $baseConfigTargetPath = $rootDir . DIRECTORY_SEPARATOR . 'config.json'; |
|
46 | - $configObject = self::getConfig($event, $baseConfigTargetPath); |
|
47 | - |
|
48 | - $configObject->{'vendorDir'} = realpath($vendorDir); |
|
49 | - $configObject->{'rootDir'} = $rootDir; |
|
50 | - $configObject->{'templateDir'} = self::createDir($event, $rootDir, 'templates'); |
|
51 | - $configObject->{'storageDir'} = self::createDir($event, $rootDir, $configObject->{'storageDir'}); |
|
52 | - $configObject->{'publicDir'} = self::createDir($event, $rootDir, 'public'); |
|
53 | - $configObject->{'jsDir'} = self::createDir($event, $rootDir, $configObject->{'publicDir'} . 'js'); |
|
54 | - $configObject->{'cssDir'} = self::createDir($event, $rootDir, $configObject->{'publicDir'} . 'css'); |
|
55 | - $configObject->{'imagesDir'} = self::createDir($event, $rootDir, $configObject->{'publicDir'} . 'images'); |
|
56 | - $configObject->{'filesDir'} = self::createDir($event, $rootDir, $configObject->{'publicDir'} . 'files'); |
|
57 | - |
|
58 | - $baseStorageDefaultPath = __DIR__ . DIRECTORY_SEPARATOR . 'install' . DIRECTORY_SEPARATOR . '_storage.json'; |
|
59 | - $baseStorageSqlPath = __DIR__ . DIRECTORY_SEPARATOR . 'install' . DIRECTORY_SEPARATOR . '_storage.sql'; |
|
60 | - |
|
61 | - self::createStorage($configObject->{'storageDir'}, $baseStorageDefaultPath, $baseStorageSqlPath); |
|
62 | - self::saveConfig($event, $baseConfigTargetPath, $configObject); |
|
63 | - self::copyInstallFile($event, 'public.htaccess', $configObject->{'publicDir'}, '.htaccess'); |
|
64 | - self::copyInstallFile($event, 'root.htaccess', $configObject->{'rootDir'}, '.htaccess'); |
|
65 | - self::copyInstallFile($event, 'base.php', $configObject->{'templateDir'}); |
|
66 | - self::copyInstallFile($event, 'cms.css', $configObject->{'cssDir'}); |
|
67 | - self::copyInstallFile($event, 'cms.js', $configObject->{'jsDir'}); |
|
68 | - self::copyInstallFile($event, 'index.php', $configObject->{'publicDir'}); |
|
69 | - |
|
70 | - $event->getIO()->write(""); |
|
71 | - $event->getIO()->write("[SUCCESS] Installation is complete"); |
|
72 | - $event->getIO()->write(""); |
|
73 | - } |
|
74 | - |
|
75 | - /** |
|
76 | - * @param Event $event |
|
77 | - * @param $baseConfigTargetPath |
|
78 | - * @param $configObject |
|
79 | - * @internal param $rootDir |
|
80 | - * @internal param $vendorDir |
|
81 | - * @internal param $templateDir |
|
82 | - * @internal param $storageDir |
|
83 | - * @internal param $baseConfigDefaultPath |
|
84 | - * @internal param $baseConfigTargetPath |
|
85 | - * @internal param $storageDir |
|
86 | - */ |
|
87 | - private static function saveConfig(Event $event, $baseConfigTargetPath, $configObject) |
|
88 | - { |
|
89 | - file_put_contents($baseConfigTargetPath, json_encode($configObject)); |
|
90 | - $event->getIO()->write("[INFO] Saved config to: " . $baseConfigTargetPath); |
|
91 | - } |
|
92 | - |
|
93 | - private static function copyInstallFile(Event $event, $sourceFileName, $destinationPath, $destinationFileName = null) |
|
94 | - { |
|
95 | - $sourceFilePath = realpath(__DIR__ . DIRECTORY_SEPARATOR . 'install/_' . $sourceFileName); |
|
96 | - |
|
97 | - |
|
98 | - if ($destinationFileName === null) { |
|
99 | - $destinationFileName = $sourceFileName; |
|
100 | - } |
|
101 | - |
|
102 | - if (file_exists($sourceFilePath) && realpath($destinationPath) !== false) { |
|
103 | - $destinationFullPath = realpath($destinationPath) . DIRECTORY_SEPARATOR . $destinationFileName; |
|
104 | - if (file_exists($destinationFullPath)) { |
|
105 | - $event->getIO()->write("[INFO] File already exists: " . $destinationFullPath); |
|
106 | - } else { |
|
107 | - copy($sourceFilePath, $destinationFullPath); |
|
108 | - $event->getIO()->write("[INSTALL] Copied file: " . $sourceFileName . ' to ' . $destinationPath); |
|
109 | - } |
|
110 | - } else { |
|
111 | - $event->getIO()->write("[ERROR] Couldnt copy file: " . $sourceFileName . ' to ' . $destinationPath); |
|
112 | - } |
|
113 | - } |
|
114 | - |
|
115 | - /** |
|
116 | - * @param $storageDir |
|
117 | - * @param $baseStorageDefaultPath |
|
118 | - * @param $baseStorageSqlPath |
|
119 | - */ |
|
120 | - private static function createStorage($storageDir, $baseStorageDefaultPath, $baseStorageSqlPath) |
|
121 | - { |
|
122 | - $repository = new Repository($storageDir); |
|
123 | - $repository->init($baseStorageDefaultPath, $baseStorageSqlPath); |
|
124 | - } |
|
125 | - |
|
126 | - private static function createDir(Event $event, $rootDir, $dirName) |
|
127 | - { |
|
128 | - $dir = $rootDir . DIRECTORY_SEPARATOR . $dirName . DIRECTORY_SEPARATOR; |
|
129 | - if (!is_dir($dir)) { |
|
130 | - mkdir($dir); |
|
131 | - $event->getIO()->write("[INSTALL] Created dir: " . $dir); |
|
132 | - } else { |
|
133 | - $event->getIO()->write("[INFO] Dir already exists: " . $dir); |
|
134 | - } |
|
135 | - return self::getRelativePath($rootDir, $dir); |
|
136 | - } |
|
137 | - |
|
138 | - /** |
|
139 | - * @param $configTargetPath |
|
140 | - * @return mixed |
|
141 | - */ |
|
142 | - private static function getConfig(Event $event, $configTargetPath) |
|
143 | - { |
|
144 | - $baseConfigDefaultPath = realpath(__DIR__ . DIRECTORY_SEPARATOR . 'install' . DIRECTORY_SEPARATOR . '_config.json'); |
|
145 | - |
|
146 | - if (file_exists($configTargetPath)) { |
|
147 | - $config = json_decode(file_get_contents($configTargetPath)); |
|
148 | - $event->getIO()->write("[INFO] Using existing config"); |
|
149 | - } else { |
|
150 | - $config = json_decode(file_get_contents($baseConfigDefaultPath)); |
|
151 | - $event->getIO()->write("[INSTALL] Created default config"); |
|
152 | - } |
|
153 | - return $config; |
|
154 | - } |
|
155 | - |
|
156 | - /** |
|
157 | - * Calculate the relative path from $from to $to |
|
158 | - * Derived from https://stackoverflow.com/a/2638272/ |
|
159 | - * |
|
160 | - * @param $from |
|
161 | - * @param $to |
|
162 | - * @return string |
|
163 | - */ |
|
164 | - private static function getRelativePath($from, $to) |
|
165 | - { |
|
166 | - // some compatibility fixes for Windows paths |
|
167 | - $from = is_dir($from) ? rtrim($from, '\/') . DIRECTORY_SEPARATOR : $from; |
|
168 | - $to = is_dir($to) ? rtrim($to, '\/') . DIRECTORY_SEPARATOR : $to; |
|
169 | - $from = str_replace('\\', DIRECTORY_SEPARATOR, $from); |
|
170 | - $to = str_replace('\\', DIRECTORY_SEPARATOR, $to); |
|
171 | - |
|
172 | - $from = explode(DIRECTORY_SEPARATOR, $from); |
|
173 | - $to = explode(DIRECTORY_SEPARATOR, $to); |
|
174 | - $relPath = $to; |
|
175 | - |
|
176 | - $relPath = self::calculateRelativePath($from, $to, $relPath); |
|
177 | - $relPath = implode(DIRECTORY_SEPARATOR, $relPath); |
|
178 | - $relPath = self::removePointerToCurrentDir($relPath); |
|
179 | - return $relPath; |
|
180 | - } |
|
181 | - |
|
182 | - /** |
|
183 | - * @param $relPath |
|
184 | - * @return mixed |
|
185 | - */ |
|
186 | - private static function removePointerToCurrentDir($relPath) |
|
187 | - { |
|
188 | - while (strpos($relPath, '.' . DIRECTORY_SEPARATOR . '.' . DIRECTORY_SEPARATOR) !== false) { |
|
189 | - $relPath = str_replace('.' . DIRECTORY_SEPARATOR . '.' . DIRECTORY_SEPARATOR, '.' . DIRECTORY_SEPARATOR, $relPath); |
|
190 | - } |
|
191 | - return $relPath; |
|
192 | - } |
|
193 | - |
|
194 | - /** |
|
195 | - * @param $from |
|
196 | - * @param $to |
|
197 | - * @param $relPath |
|
198 | - * @return array |
|
199 | - */ |
|
200 | - private static function calculateRelativePath($from, $to, $relPath) |
|
201 | - { |
|
202 | - foreach ($from as $depth => $dir) { |
|
203 | - // find first non-matching dir |
|
204 | - if ($dir === $to[$depth]) { |
|
205 | - // ignore this directory |
|
206 | - array_shift($relPath); |
|
207 | - } else { |
|
208 | - // get number of remaining dirs to $from |
|
209 | - $remaining = count($from) - $depth; |
|
210 | - if ($remaining > 1) { |
|
211 | - // add traversals up to first matching dir |
|
212 | - $padLength = (count($relPath) + $remaining - 1) * -1; |
|
213 | - $relPath = array_pad($relPath, $padLength, '..'); |
|
214 | - break; |
|
215 | - } else { |
|
216 | - $relPath[0] = '.' . DIRECTORY_SEPARATOR . $relPath[0]; |
|
217 | - } |
|
218 | - } |
|
219 | - } |
|
220 | - return $relPath; |
|
221 | - } |
|
14 | + public static function run() |
|
15 | + { |
|
16 | + new Application(); |
|
17 | + } |
|
18 | + |
|
19 | + public static function postInstall(Event $event) |
|
20 | + { |
|
21 | + $event->getIO()->write("Post install"); |
|
22 | + self::checkInstall($event); |
|
23 | + } |
|
24 | + |
|
25 | + public static function postUpdate(Event $event) |
|
26 | + { |
|
27 | + $event->getIO()->write("Post update"); |
|
28 | + self::checkInstall($event); |
|
29 | + } |
|
30 | + |
|
31 | + /** |
|
32 | + * @param Event $event |
|
33 | + */ |
|
34 | + private static function checkInstall(Event $event) |
|
35 | + { |
|
36 | + $event->getIO()->write(""); |
|
37 | + $event->getIO()->write("********************************************************"); |
|
38 | + $event->getIO()->write("*** Checking installation of Cloud Control framework ***"); |
|
39 | + $event->getIO()->write("********************************************************"); |
|
40 | + $event->getIO()->write(""); |
|
41 | + |
|
42 | + $vendorDir = $event->getComposer()->getConfig()->get('vendor-dir'); |
|
43 | + $rootDir = realpath($vendorDir . DIRECTORY_SEPARATOR . '..' . DIRECTORY_SEPARATOR); |
|
44 | + |
|
45 | + $baseConfigTargetPath = $rootDir . DIRECTORY_SEPARATOR . 'config.json'; |
|
46 | + $configObject = self::getConfig($event, $baseConfigTargetPath); |
|
47 | + |
|
48 | + $configObject->{'vendorDir'} = realpath($vendorDir); |
|
49 | + $configObject->{'rootDir'} = $rootDir; |
|
50 | + $configObject->{'templateDir'} = self::createDir($event, $rootDir, 'templates'); |
|
51 | + $configObject->{'storageDir'} = self::createDir($event, $rootDir, $configObject->{'storageDir'}); |
|
52 | + $configObject->{'publicDir'} = self::createDir($event, $rootDir, 'public'); |
|
53 | + $configObject->{'jsDir'} = self::createDir($event, $rootDir, $configObject->{'publicDir'} . 'js'); |
|
54 | + $configObject->{'cssDir'} = self::createDir($event, $rootDir, $configObject->{'publicDir'} . 'css'); |
|
55 | + $configObject->{'imagesDir'} = self::createDir($event, $rootDir, $configObject->{'publicDir'} . 'images'); |
|
56 | + $configObject->{'filesDir'} = self::createDir($event, $rootDir, $configObject->{'publicDir'} . 'files'); |
|
57 | + |
|
58 | + $baseStorageDefaultPath = __DIR__ . DIRECTORY_SEPARATOR . 'install' . DIRECTORY_SEPARATOR . '_storage.json'; |
|
59 | + $baseStorageSqlPath = __DIR__ . DIRECTORY_SEPARATOR . 'install' . DIRECTORY_SEPARATOR . '_storage.sql'; |
|
60 | + |
|
61 | + self::createStorage($configObject->{'storageDir'}, $baseStorageDefaultPath, $baseStorageSqlPath); |
|
62 | + self::saveConfig($event, $baseConfigTargetPath, $configObject); |
|
63 | + self::copyInstallFile($event, 'public.htaccess', $configObject->{'publicDir'}, '.htaccess'); |
|
64 | + self::copyInstallFile($event, 'root.htaccess', $configObject->{'rootDir'}, '.htaccess'); |
|
65 | + self::copyInstallFile($event, 'base.php', $configObject->{'templateDir'}); |
|
66 | + self::copyInstallFile($event, 'cms.css', $configObject->{'cssDir'}); |
|
67 | + self::copyInstallFile($event, 'cms.js', $configObject->{'jsDir'}); |
|
68 | + self::copyInstallFile($event, 'index.php', $configObject->{'publicDir'}); |
|
69 | + |
|
70 | + $event->getIO()->write(""); |
|
71 | + $event->getIO()->write("[SUCCESS] Installation is complete"); |
|
72 | + $event->getIO()->write(""); |
|
73 | + } |
|
74 | + |
|
75 | + /** |
|
76 | + * @param Event $event |
|
77 | + * @param $baseConfigTargetPath |
|
78 | + * @param $configObject |
|
79 | + * @internal param $rootDir |
|
80 | + * @internal param $vendorDir |
|
81 | + * @internal param $templateDir |
|
82 | + * @internal param $storageDir |
|
83 | + * @internal param $baseConfigDefaultPath |
|
84 | + * @internal param $baseConfigTargetPath |
|
85 | + * @internal param $storageDir |
|
86 | + */ |
|
87 | + private static function saveConfig(Event $event, $baseConfigTargetPath, $configObject) |
|
88 | + { |
|
89 | + file_put_contents($baseConfigTargetPath, json_encode($configObject)); |
|
90 | + $event->getIO()->write("[INFO] Saved config to: " . $baseConfigTargetPath); |
|
91 | + } |
|
92 | + |
|
93 | + private static function copyInstallFile(Event $event, $sourceFileName, $destinationPath, $destinationFileName = null) |
|
94 | + { |
|
95 | + $sourceFilePath = realpath(__DIR__ . DIRECTORY_SEPARATOR . 'install/_' . $sourceFileName); |
|
96 | + |
|
97 | + |
|
98 | + if ($destinationFileName === null) { |
|
99 | + $destinationFileName = $sourceFileName; |
|
100 | + } |
|
101 | + |
|
102 | + if (file_exists($sourceFilePath) && realpath($destinationPath) !== false) { |
|
103 | + $destinationFullPath = realpath($destinationPath) . DIRECTORY_SEPARATOR . $destinationFileName; |
|
104 | + if (file_exists($destinationFullPath)) { |
|
105 | + $event->getIO()->write("[INFO] File already exists: " . $destinationFullPath); |
|
106 | + } else { |
|
107 | + copy($sourceFilePath, $destinationFullPath); |
|
108 | + $event->getIO()->write("[INSTALL] Copied file: " . $sourceFileName . ' to ' . $destinationPath); |
|
109 | + } |
|
110 | + } else { |
|
111 | + $event->getIO()->write("[ERROR] Couldnt copy file: " . $sourceFileName . ' to ' . $destinationPath); |
|
112 | + } |
|
113 | + } |
|
114 | + |
|
115 | + /** |
|
116 | + * @param $storageDir |
|
117 | + * @param $baseStorageDefaultPath |
|
118 | + * @param $baseStorageSqlPath |
|
119 | + */ |
|
120 | + private static function createStorage($storageDir, $baseStorageDefaultPath, $baseStorageSqlPath) |
|
121 | + { |
|
122 | + $repository = new Repository($storageDir); |
|
123 | + $repository->init($baseStorageDefaultPath, $baseStorageSqlPath); |
|
124 | + } |
|
125 | + |
|
126 | + private static function createDir(Event $event, $rootDir, $dirName) |
|
127 | + { |
|
128 | + $dir = $rootDir . DIRECTORY_SEPARATOR . $dirName . DIRECTORY_SEPARATOR; |
|
129 | + if (!is_dir($dir)) { |
|
130 | + mkdir($dir); |
|
131 | + $event->getIO()->write("[INSTALL] Created dir: " . $dir); |
|
132 | + } else { |
|
133 | + $event->getIO()->write("[INFO] Dir already exists: " . $dir); |
|
134 | + } |
|
135 | + return self::getRelativePath($rootDir, $dir); |
|
136 | + } |
|
137 | + |
|
138 | + /** |
|
139 | + * @param $configTargetPath |
|
140 | + * @return mixed |
|
141 | + */ |
|
142 | + private static function getConfig(Event $event, $configTargetPath) |
|
143 | + { |
|
144 | + $baseConfigDefaultPath = realpath(__DIR__ . DIRECTORY_SEPARATOR . 'install' . DIRECTORY_SEPARATOR . '_config.json'); |
|
145 | + |
|
146 | + if (file_exists($configTargetPath)) { |
|
147 | + $config = json_decode(file_get_contents($configTargetPath)); |
|
148 | + $event->getIO()->write("[INFO] Using existing config"); |
|
149 | + } else { |
|
150 | + $config = json_decode(file_get_contents($baseConfigDefaultPath)); |
|
151 | + $event->getIO()->write("[INSTALL] Created default config"); |
|
152 | + } |
|
153 | + return $config; |
|
154 | + } |
|
155 | + |
|
156 | + /** |
|
157 | + * Calculate the relative path from $from to $to |
|
158 | + * Derived from https://stackoverflow.com/a/2638272/ |
|
159 | + * |
|
160 | + * @param $from |
|
161 | + * @param $to |
|
162 | + * @return string |
|
163 | + */ |
|
164 | + private static function getRelativePath($from, $to) |
|
165 | + { |
|
166 | + // some compatibility fixes for Windows paths |
|
167 | + $from = is_dir($from) ? rtrim($from, '\/') . DIRECTORY_SEPARATOR : $from; |
|
168 | + $to = is_dir($to) ? rtrim($to, '\/') . DIRECTORY_SEPARATOR : $to; |
|
169 | + $from = str_replace('\\', DIRECTORY_SEPARATOR, $from); |
|
170 | + $to = str_replace('\\', DIRECTORY_SEPARATOR, $to); |
|
171 | + |
|
172 | + $from = explode(DIRECTORY_SEPARATOR, $from); |
|
173 | + $to = explode(DIRECTORY_SEPARATOR, $to); |
|
174 | + $relPath = $to; |
|
175 | + |
|
176 | + $relPath = self::calculateRelativePath($from, $to, $relPath); |
|
177 | + $relPath = implode(DIRECTORY_SEPARATOR, $relPath); |
|
178 | + $relPath = self::removePointerToCurrentDir($relPath); |
|
179 | + return $relPath; |
|
180 | + } |
|
181 | + |
|
182 | + /** |
|
183 | + * @param $relPath |
|
184 | + * @return mixed |
|
185 | + */ |
|
186 | + private static function removePointerToCurrentDir($relPath) |
|
187 | + { |
|
188 | + while (strpos($relPath, '.' . DIRECTORY_SEPARATOR . '.' . DIRECTORY_SEPARATOR) !== false) { |
|
189 | + $relPath = str_replace('.' . DIRECTORY_SEPARATOR . '.' . DIRECTORY_SEPARATOR, '.' . DIRECTORY_SEPARATOR, $relPath); |
|
190 | + } |
|
191 | + return $relPath; |
|
192 | + } |
|
193 | + |
|
194 | + /** |
|
195 | + * @param $from |
|
196 | + * @param $to |
|
197 | + * @param $relPath |
|
198 | + * @return array |
|
199 | + */ |
|
200 | + private static function calculateRelativePath($from, $to, $relPath) |
|
201 | + { |
|
202 | + foreach ($from as $depth => $dir) { |
|
203 | + // find first non-matching dir |
|
204 | + if ($dir === $to[$depth]) { |
|
205 | + // ignore this directory |
|
206 | + array_shift($relPath); |
|
207 | + } else { |
|
208 | + // get number of remaining dirs to $from |
|
209 | + $remaining = count($from) - $depth; |
|
210 | + if ($remaining > 1) { |
|
211 | + // add traversals up to first matching dir |
|
212 | + $padLength = (count($relPath) + $remaining - 1) * -1; |
|
213 | + $relPath = array_pad($relPath, $padLength, '..'); |
|
214 | + break; |
|
215 | + } else { |
|
216 | + $relPath[0] = '.' . DIRECTORY_SEPARATOR . $relPath[0]; |
|
217 | + } |
|
218 | + } |
|
219 | + } |
|
220 | + return $relPath; |
|
221 | + } |
|
222 | 222 | |
223 | 223 | } |
224 | 224 | \ No newline at end of file |
@@ -40,9 +40,9 @@ discard block |
||
40 | 40 | $event->getIO()->write(""); |
41 | 41 | |
42 | 42 | $vendorDir = $event->getComposer()->getConfig()->get('vendor-dir'); |
43 | - $rootDir = realpath($vendorDir . DIRECTORY_SEPARATOR . '..' . DIRECTORY_SEPARATOR); |
|
43 | + $rootDir = realpath($vendorDir.DIRECTORY_SEPARATOR.'..'.DIRECTORY_SEPARATOR); |
|
44 | 44 | |
45 | - $baseConfigTargetPath = $rootDir . DIRECTORY_SEPARATOR . 'config.json'; |
|
45 | + $baseConfigTargetPath = $rootDir.DIRECTORY_SEPARATOR.'config.json'; |
|
46 | 46 | $configObject = self::getConfig($event, $baseConfigTargetPath); |
47 | 47 | |
48 | 48 | $configObject->{'vendorDir'} = realpath($vendorDir); |
@@ -50,13 +50,13 @@ discard block |
||
50 | 50 | $configObject->{'templateDir'} = self::createDir($event, $rootDir, 'templates'); |
51 | 51 | $configObject->{'storageDir'} = self::createDir($event, $rootDir, $configObject->{'storageDir'}); |
52 | 52 | $configObject->{'publicDir'} = self::createDir($event, $rootDir, 'public'); |
53 | - $configObject->{'jsDir'} = self::createDir($event, $rootDir, $configObject->{'publicDir'} . 'js'); |
|
54 | - $configObject->{'cssDir'} = self::createDir($event, $rootDir, $configObject->{'publicDir'} . 'css'); |
|
55 | - $configObject->{'imagesDir'} = self::createDir($event, $rootDir, $configObject->{'publicDir'} . 'images'); |
|
56 | - $configObject->{'filesDir'} = self::createDir($event, $rootDir, $configObject->{'publicDir'} . 'files'); |
|
53 | + $configObject->{'jsDir'} = self::createDir($event, $rootDir, $configObject->{'publicDir'}.'js'); |
|
54 | + $configObject->{'cssDir'} = self::createDir($event, $rootDir, $configObject->{'publicDir'}.'css'); |
|
55 | + $configObject->{'imagesDir'} = self::createDir($event, $rootDir, $configObject->{'publicDir'}.'images'); |
|
56 | + $configObject->{'filesDir'} = self::createDir($event, $rootDir, $configObject->{'publicDir'}.'files'); |
|
57 | 57 | |
58 | - $baseStorageDefaultPath = __DIR__ . DIRECTORY_SEPARATOR . 'install' . DIRECTORY_SEPARATOR . '_storage.json'; |
|
59 | - $baseStorageSqlPath = __DIR__ . DIRECTORY_SEPARATOR . 'install' . DIRECTORY_SEPARATOR . '_storage.sql'; |
|
58 | + $baseStorageDefaultPath = __DIR__.DIRECTORY_SEPARATOR.'install'.DIRECTORY_SEPARATOR.'_storage.json'; |
|
59 | + $baseStorageSqlPath = __DIR__.DIRECTORY_SEPARATOR.'install'.DIRECTORY_SEPARATOR.'_storage.sql'; |
|
60 | 60 | |
61 | 61 | self::createStorage($configObject->{'storageDir'}, $baseStorageDefaultPath, $baseStorageSqlPath); |
62 | 62 | self::saveConfig($event, $baseConfigTargetPath, $configObject); |
@@ -87,12 +87,12 @@ discard block |
||
87 | 87 | private static function saveConfig(Event $event, $baseConfigTargetPath, $configObject) |
88 | 88 | { |
89 | 89 | file_put_contents($baseConfigTargetPath, json_encode($configObject)); |
90 | - $event->getIO()->write("[INFO] Saved config to: " . $baseConfigTargetPath); |
|
90 | + $event->getIO()->write("[INFO] Saved config to: ".$baseConfigTargetPath); |
|
91 | 91 | } |
92 | 92 | |
93 | 93 | private static function copyInstallFile(Event $event, $sourceFileName, $destinationPath, $destinationFileName = null) |
94 | 94 | { |
95 | - $sourceFilePath = realpath(__DIR__ . DIRECTORY_SEPARATOR . 'install/_' . $sourceFileName); |
|
95 | + $sourceFilePath = realpath(__DIR__.DIRECTORY_SEPARATOR.'install/_'.$sourceFileName); |
|
96 | 96 | |
97 | 97 | |
98 | 98 | if ($destinationFileName === null) { |
@@ -100,15 +100,15 @@ discard block |
||
100 | 100 | } |
101 | 101 | |
102 | 102 | if (file_exists($sourceFilePath) && realpath($destinationPath) !== false) { |
103 | - $destinationFullPath = realpath($destinationPath) . DIRECTORY_SEPARATOR . $destinationFileName; |
|
103 | + $destinationFullPath = realpath($destinationPath).DIRECTORY_SEPARATOR.$destinationFileName; |
|
104 | 104 | if (file_exists($destinationFullPath)) { |
105 | - $event->getIO()->write("[INFO] File already exists: " . $destinationFullPath); |
|
105 | + $event->getIO()->write("[INFO] File already exists: ".$destinationFullPath); |
|
106 | 106 | } else { |
107 | 107 | copy($sourceFilePath, $destinationFullPath); |
108 | - $event->getIO()->write("[INSTALL] Copied file: " . $sourceFileName . ' to ' . $destinationPath); |
|
108 | + $event->getIO()->write("[INSTALL] Copied file: ".$sourceFileName.' to '.$destinationPath); |
|
109 | 109 | } |
110 | 110 | } else { |
111 | - $event->getIO()->write("[ERROR] Couldnt copy file: " . $sourceFileName . ' to ' . $destinationPath); |
|
111 | + $event->getIO()->write("[ERROR] Couldnt copy file: ".$sourceFileName.' to '.$destinationPath); |
|
112 | 112 | } |
113 | 113 | } |
114 | 114 | |
@@ -125,12 +125,12 @@ discard block |
||
125 | 125 | |
126 | 126 | private static function createDir(Event $event, $rootDir, $dirName) |
127 | 127 | { |
128 | - $dir = $rootDir . DIRECTORY_SEPARATOR . $dirName . DIRECTORY_SEPARATOR; |
|
128 | + $dir = $rootDir.DIRECTORY_SEPARATOR.$dirName.DIRECTORY_SEPARATOR; |
|
129 | 129 | if (!is_dir($dir)) { |
130 | 130 | mkdir($dir); |
131 | - $event->getIO()->write("[INSTALL] Created dir: " . $dir); |
|
131 | + $event->getIO()->write("[INSTALL] Created dir: ".$dir); |
|
132 | 132 | } else { |
133 | - $event->getIO()->write("[INFO] Dir already exists: " . $dir); |
|
133 | + $event->getIO()->write("[INFO] Dir already exists: ".$dir); |
|
134 | 134 | } |
135 | 135 | return self::getRelativePath($rootDir, $dir); |
136 | 136 | } |
@@ -141,7 +141,7 @@ discard block |
||
141 | 141 | */ |
142 | 142 | private static function getConfig(Event $event, $configTargetPath) |
143 | 143 | { |
144 | - $baseConfigDefaultPath = realpath(__DIR__ . DIRECTORY_SEPARATOR . 'install' . DIRECTORY_SEPARATOR . '_config.json'); |
|
144 | + $baseConfigDefaultPath = realpath(__DIR__.DIRECTORY_SEPARATOR.'install'.DIRECTORY_SEPARATOR.'_config.json'); |
|
145 | 145 | |
146 | 146 | if (file_exists($configTargetPath)) { |
147 | 147 | $config = json_decode(file_get_contents($configTargetPath)); |
@@ -164,8 +164,8 @@ discard block |
||
164 | 164 | private static function getRelativePath($from, $to) |
165 | 165 | { |
166 | 166 | // some compatibility fixes for Windows paths |
167 | - $from = is_dir($from) ? rtrim($from, '\/') . DIRECTORY_SEPARATOR : $from; |
|
168 | - $to = is_dir($to) ? rtrim($to, '\/') . DIRECTORY_SEPARATOR : $to; |
|
167 | + $from = is_dir($from) ? rtrim($from, '\/').DIRECTORY_SEPARATOR : $from; |
|
168 | + $to = is_dir($to) ? rtrim($to, '\/').DIRECTORY_SEPARATOR : $to; |
|
169 | 169 | $from = str_replace('\\', DIRECTORY_SEPARATOR, $from); |
170 | 170 | $to = str_replace('\\', DIRECTORY_SEPARATOR, $to); |
171 | 171 | |
@@ -185,8 +185,8 @@ discard block |
||
185 | 185 | */ |
186 | 186 | private static function removePointerToCurrentDir($relPath) |
187 | 187 | { |
188 | - while (strpos($relPath, '.' . DIRECTORY_SEPARATOR . '.' . DIRECTORY_SEPARATOR) !== false) { |
|
189 | - $relPath = str_replace('.' . DIRECTORY_SEPARATOR . '.' . DIRECTORY_SEPARATOR, '.' . DIRECTORY_SEPARATOR, $relPath); |
|
188 | + while (strpos($relPath, '.'.DIRECTORY_SEPARATOR.'.'.DIRECTORY_SEPARATOR) !== false) { |
|
189 | + $relPath = str_replace('.'.DIRECTORY_SEPARATOR.'.'.DIRECTORY_SEPARATOR, '.'.DIRECTORY_SEPARATOR, $relPath); |
|
190 | 190 | } |
191 | 191 | return $relPath; |
192 | 192 | } |
@@ -213,7 +213,7 @@ discard block |
||
213 | 213 | $relPath = array_pad($relPath, $padLength, '..'); |
214 | 214 | break; |
215 | 215 | } else { |
216 | - $relPath[0] = '.' . DIRECTORY_SEPARATOR . $relPath[0]; |
|
216 | + $relPath[0] = '.'.DIRECTORY_SEPARATOR.$relPath[0]; |
|
217 | 217 | } |
218 | 218 | } |
219 | 219 | } |
@@ -9,15 +9,15 @@ discard block |
||
9 | 9 | */ |
10 | 10 | function dump() |
11 | 11 | { |
12 | - $debug_backtrace = current(debug_backtrace()); |
|
13 | - if (PHP_SAPI == 'cli') { |
|
14 | - echo 'Dump: ' . $debug_backtrace['file'] . ':' . $debug_backtrace['line'] . "\n"; |
|
15 | - foreach (func_get_args() as $data) { |
|
16 | - var_dump($data); |
|
17 | - } |
|
18 | - } else { |
|
19 | - ob_clean(); |
|
20 | - echo <<<END |
|
12 | + $debug_backtrace = current(debug_backtrace()); |
|
13 | + if (PHP_SAPI == 'cli') { |
|
14 | + echo 'Dump: ' . $debug_backtrace['file'] . ':' . $debug_backtrace['line'] . "\n"; |
|
15 | + foreach (func_get_args() as $data) { |
|
16 | + var_dump($data); |
|
17 | + } |
|
18 | + } else { |
|
19 | + ob_clean(); |
|
20 | + echo <<<END |
|
21 | 21 | <!DOCTYPE html> |
22 | 22 | <html> |
23 | 23 | <head> |
@@ -29,20 +29,20 @@ discard block |
||
29 | 29 | <body> |
30 | 30 | END; |
31 | 31 | |
32 | - echo '<div>Dump: ' . $debug_backtrace['file'] . ':<b>' . $debug_backtrace['line'] . "</b></div>"; |
|
33 | - echo '<pre>'; |
|
34 | - foreach (func_get_args() as $data) { |
|
35 | - echo "<code>"; |
|
36 | - var_dump($data); |
|
37 | - echo "</code>"; |
|
38 | - } |
|
39 | - echo '</pre>'; |
|
40 | - echo <<<END |
|
32 | + echo '<div>Dump: ' . $debug_backtrace['file'] . ':<b>' . $debug_backtrace['line'] . "</b></div>"; |
|
33 | + echo '<pre>'; |
|
34 | + foreach (func_get_args() as $data) { |
|
35 | + echo "<code>"; |
|
36 | + var_dump($data); |
|
37 | + echo "</code>"; |
|
38 | + } |
|
39 | + echo '</pre>'; |
|
40 | + echo <<<END |
|
41 | 41 | </body> |
42 | 42 | </html> |
43 | 43 | END; |
44 | - } |
|
45 | - die; |
|
44 | + } |
|
45 | + die; |
|
46 | 46 | } |
47 | 47 | |
48 | 48 | /** |
@@ -53,27 +53,27 @@ discard block |
||
53 | 53 | */ |
54 | 54 | function sanitize_output($buffer) |
55 | 55 | { |
56 | - if (!isset($_GET['unsanitized'])) { |
|
57 | - $search = array( |
|
58 | - '/\>[^\S ]+/s', // strip whitespaces after tags, except space |
|
59 | - '/[^\S ]+\</s', // strip whitespaces before tags, except space |
|
60 | - '/(\s)+/s', // shorten multiple whitespace sequences |
|
61 | - '/<!--(.|\s)*?-->/' // Remove HTML comments |
|
62 | - ); |
|
56 | + if (!isset($_GET['unsanitized'])) { |
|
57 | + $search = array( |
|
58 | + '/\>[^\S ]+/s', // strip whitespaces after tags, except space |
|
59 | + '/[^\S ]+\</s', // strip whitespaces before tags, except space |
|
60 | + '/(\s)+/s', // shorten multiple whitespace sequences |
|
61 | + '/<!--(.|\s)*?-->/' // Remove HTML comments |
|
62 | + ); |
|
63 | 63 | |
64 | - $replace = array( |
|
65 | - '>', |
|
66 | - '<', |
|
67 | - '\\1', |
|
68 | - '' |
|
69 | - ); |
|
64 | + $replace = array( |
|
65 | + '>', |
|
66 | + '<', |
|
67 | + '\\1', |
|
68 | + '' |
|
69 | + ); |
|
70 | 70 | |
71 | - $buffer = preg_replace($search, $replace, $buffer); |
|
71 | + $buffer = preg_replace($search, $replace, $buffer); |
|
72 | 72 | |
73 | - return $buffer; |
|
74 | - } else { |
|
75 | - return $buffer; |
|
76 | - } |
|
73 | + return $buffer; |
|
74 | + } else { |
|
75 | + return $buffer; |
|
76 | + } |
|
77 | 77 | } |
78 | 78 | |
79 | 79 | |
@@ -85,11 +85,11 @@ discard block |
||
85 | 85 | */ |
86 | 86 | function utf8Convert($array) |
87 | 87 | { |
88 | - array_walk_recursive($array, function (&$item) { |
|
89 | - if (!mb_detect_encoding($item, 'utf-8', true)) { |
|
90 | - $item = utf8_encode($item); |
|
91 | - } |
|
92 | - }); |
|
88 | + array_walk_recursive($array, function (&$item) { |
|
89 | + if (!mb_detect_encoding($item, 'utf-8', true)) { |
|
90 | + $item = utf8_encode($item); |
|
91 | + } |
|
92 | + }); |
|
93 | 93 | |
94 | - return $array; |
|
94 | + return $array; |
|
95 | 95 | } |
96 | 96 | \ No newline at end of file |
@@ -11,7 +11,7 @@ discard block |
||
11 | 11 | { |
12 | 12 | $debug_backtrace = current(debug_backtrace()); |
13 | 13 | if (PHP_SAPI == 'cli') { |
14 | - echo 'Dump: ' . $debug_backtrace['file'] . ':' . $debug_backtrace['line'] . "\n"; |
|
14 | + echo 'Dump: '.$debug_backtrace['file'].':'.$debug_backtrace['line']."\n"; |
|
15 | 15 | foreach (func_get_args() as $data) { |
16 | 16 | var_dump($data); |
17 | 17 | } |
@@ -29,7 +29,7 @@ discard block |
||
29 | 29 | <body> |
30 | 30 | END; |
31 | 31 | |
32 | - echo '<div>Dump: ' . $debug_backtrace['file'] . ':<b>' . $debug_backtrace['line'] . "</b></div>"; |
|
32 | + echo '<div>Dump: '.$debug_backtrace['file'].':<b>'.$debug_backtrace['line']."</b></div>"; |
|
33 | 33 | echo '<pre>'; |
34 | 34 | foreach (func_get_args() as $data) { |
35 | 35 | echo "<code>"; |
@@ -55,9 +55,9 @@ discard block |
||
55 | 55 | { |
56 | 56 | if (!isset($_GET['unsanitized'])) { |
57 | 57 | $search = array( |
58 | - '/\>[^\S ]+/s', // strip whitespaces after tags, except space |
|
59 | - '/[^\S ]+\</s', // strip whitespaces before tags, except space |
|
60 | - '/(\s)+/s', // shorten multiple whitespace sequences |
|
58 | + '/\>[^\S ]+/s', // strip whitespaces after tags, except space |
|
59 | + '/[^\S ]+\</s', // strip whitespaces before tags, except space |
|
60 | + '/(\s)+/s', // shorten multiple whitespace sequences |
|
61 | 61 | '/<!--(.|\s)*?-->/' // Remove HTML comments |
62 | 62 | ); |
63 | 63 | |
@@ -85,7 +85,7 @@ discard block |
||
85 | 85 | */ |
86 | 86 | function utf8Convert($array) |
87 | 87 | { |
88 | - array_walk_recursive($array, function (&$item) { |
|
88 | + array_walk_recursive($array, function(&$item) { |
|
89 | 89 | if (!mb_detect_encoding($item, 'utf-8', true)) { |
90 | 90 | $item = utf8_encode($item); |
91 | 91 | } |